π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Speed up tests to ~3 minutes. (#316)
Peter Sobot08bbe8ba28ea
diff --git a/.github/workflows/all.yml b/.github/workflows/all.ymlindex b8bfe99..2dd5e7a 100644--- a/.github/workflows/all.yml+++ b/.github/workflows/all.yml@@ -18,37 +18,30 @@ jobs:continue-on-error: truestrategy:matrix:- python-version: ['3.11']+ python-version: ['3.12']os: ['ubuntu-20.04']name: Lint Pythonsteps:- name: Set up Python ${{ matrix.python-version }}- uses: actions/setup-python@v2+ uses: actions/setup-python@v5with:python-version: ${{ matrix.python-version }}- - uses: actions/checkout@v2- with:- submodules: recursive- - name: Install lint dependencies- env:- # on macOS and with Python 3.10: building NumPy from source fails without these options:- NPY_BLAS_ORDER: ""- NPY_LAPACK_ORDER: ""+ - uses: actions/checkout@v4+ - name: Install Ruffrun: |python -m pip install --upgrade pip- pip install wheel- pip install -r test-requirements.txt+ pip install ruff- name: Lint Python code- run: flake8 . --count --ignore=W503,E203 --exclude .git,dist,doc,build,vendors --show-source --statistics --max-line-length 100+ run: ruff check ${{ runner.workspace }}/pedalboard --ignore=E203,F541 --exclude .git,dist,doc,build,vendors,'*.pyi' --line-length 100- name: Check Python formatting- run: black pedalboard tests --line-length 100 --preview --diff --check+ run: ruff format --check ${{ runner.workspace }}/pedalboard --exclude .git,dist,doc,build,JUCE,examples,vendors,'*.pyi' --diff --line-length 100lint-cpp:runs-on: 'ubuntu-20.04'continue-on-error: truename: Lint C++steps:- - uses: actions/checkout@v2+ - uses: actions/checkout@v4# Don't check out submodules, as the action below will look at ALL C++ code!- name: Check C++ Formattinguses: jidicula/[email protected]@@ -56,22 +49,403 @@ jobs:clang-format-version: 14fallback-style: LLVM+ # Build the native module with ccache enabled so we can share object files between builds:+ prime-ubuntu-build-caches:+ runs-on: ${{ matrix.os }}+ continue-on-error: false+ strategy:+ matrix:+ include:+ - { os: ubuntu-20.04, python-version: "3.12", compiler: "gcc", cc: "ccache gcc", cxx: "ccache g++" }+ name: Pre-build on ${{ matrix.os }} with ${{ matrix.compiler }}+ steps:+ - name: Set up Python ${{ matrix.python-version }}+ uses: actions/setup-python@v5+ with:+ python-version: ${{ matrix.python-version }}+ - uses: actions/checkout@v4+ with:+ submodules: recursive+ - name: Install Linux dependencies+ if: runner.os == 'Linux'+ run: |+ sudo apt-get update \+ && sudo apt-get install -y pkg-config libsndfile1 \+ libx11-dev libxrandr-dev libxinerama-dev \+ libxrender-dev libxcomposite-dev libxcb-xinerama0-dev \+ libxcursor-dev libfreetype6 libfreetype6-dev+ # We depend on ccache features that are only present in 4.8.0 and later, but installing from apt-get gives us v3.+ - name: Install ccache on Linux+ if: runner.os == 'Linux'+ run: |+ mkdir ccache+ curl -L https://github.com/ccache/ccache/releases/download/v4.9.1/ccache-4.9.1-linux-x86_64.tar.xz | tar xvJf - -C ccache+ mv ccache/ccache*/ccache /usr/local/bin/ccache+ chmod +x /usr/local/bin/ccache+ - name: Install ccache on macOS+ if: runner.os == 'macOS'+ run: brew install ccache+ - name: Install test dependencies+ env:+ # on macOS and with Python 3.10: building NumPy from source fails without these options:+ NPY_BLAS_ORDER: ""+ NPY_LAPACK_ORDER: ""+ run: |+ python -m pip install --upgrade pip+ pip install wheel+ pip install -r test-requirements.txt+ # TensorFlow is an optional dependency; if present, we'll run tests with it:+ # There are no environment specifiers to select when TensorFlow binaries are available.+ pip install tensorflow==2.13 || true+ - name: Restore Cached ${{ runner.os }} Objects+ id: cache-objects-restore+ uses: actions/cache/restore@v4+ with:+ path: ${{ runner.workspace }}/.ccache+ key: ${{ runner.os }}-${{ matrix.compiler }}-ccache+ - name: Build pedalboard locally+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ CCACHE_BASEDIR: ${{ runner.workspace }}+ CCACHE_DEBUGDIR: ${{ runner.workspace }}/.ccache_debug+ CCACHE_SLOPPINESS: "pch_defines,include_file_mtime,include_file_ctime,time_macros,locale,random_seed,system_headers"+ CCACHE_COMPILERCHECK: none+ CCACHE_NOINODECACHE: 1+ CCACHE_IGNOREOPTIONS: "-fno-strict-overflow -fwrapv -W* -arch x86_64 arm64 -dynamic -fno-common -g -I/usr/local/opt/*"+ CCACHE_LOGFILE: ${{ runner.workspace }}/.ccache_log+ CCACHE_DEBUG: "1"+ DISABLE_LTO: "1" # Speeds up un-cacheable link step which doesn't really increase performance in tests anyways+ CC: ${{ matrix.cc }}+ CXX: ${{ matrix.cxx }}+ run: python setup.py develop+ - name: Ensure ccache worked+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ run: |+ ccache --show-stats --verbose+ ccache --zero-stats+ cat ${{ runner.workspace }}/.ccache_log || true+ - name: Save Cached ${{ runner.os }} Objects+ id: cache-objects-save+ uses: actions/cache/save@v4+ with:+ path: |+ ${{ runner.workspace }}/.ccache+ ${{ runner.workspace }}/pedalboard/build/lib*+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/pedalboard/juce_overrides+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/vendors+ key: ${{ steps.cache-objects-restore.outputs.cache-primary-key }}++ prime-macos-build-caches:+ runs-on: ${{ matrix.os }}+ continue-on-error: false+ strategy:+ matrix:+ include:+ - { os: macos-13, python-version: "3.12", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ name: Pre-build on ${{ matrix.os }} with ${{ matrix.compiler }}+ steps:+ - name: Set up Python ${{ matrix.python-version }}+ uses: actions/setup-python@v5+ with:+ python-version: ${{ matrix.python-version }}+ - uses: actions/checkout@v4+ with:+ submodules: recursive+ - name: Install ccache on macOS+ if: runner.os == 'macOS'+ run: brew install ccache+ - name: Install test dependencies+ env:+ # on macOS and with Python 3.10: building NumPy from source fails without these options:+ NPY_BLAS_ORDER: ""+ NPY_LAPACK_ORDER: ""+ run: |+ python -m pip install --upgrade pip+ pip install wheel+ pip install -r test-requirements.txt+ - name: Restore Cached ${{ runner.os }} Objects+ id: cache-objects-restore+ uses: actions/cache/restore@v4+ with:+ path: ${{ runner.workspace }}/.ccache+ key: ${{ runner.os }}-${{ matrix.compiler }}-ccache+ - name: Build pedalboard locally+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ CCACHE_BASEDIR: ${{ runner.workspace }}+ CCACHE_DEBUGDIR: ${{ runner.workspace }}/.ccache_debug+ CCACHE_SLOPPINESS: "pch_defines,include_file_mtime,include_file_ctime,time_macros,locale,random_seed,system_headers"+ CCACHE_COMPILERCHECK: none+ CCACHE_NOINODECACHE: 1+ CCACHE_IGNOREOPTIONS: "-fno-strict-overflow -fwrapv -W* -arch x86_64 arm64 -dynamic -fno-common -g -I/usr/local/opt/*"+ CCACHE_DEBUG: "1"+ MACOSX_DEPLOYMENT_TARGET: "10.13"+ CCACHE_LOGFILE: ${{ runner.workspace }}/.ccache_log+ # This build caching is only to speed up tests on CI, so we only care about x86_64 for now.+ # Without limiting to a single architecture, ccache can't properly cache mixed Objective-C and C++ builds.+ # Fun fact: this is supported in Python itself! https://github.com/python/cpython/blob/893c9cc/Lib/_osx_support.py#L314-L328+ ARCHFLAGS: -arch x86_64+ DISABLE_LTO: "1" # Speeds up un-cacheable link step which doesn't really increase performance in tests anyways+ CC: ${{ matrix.cc }}+ CXX: ${{ matrix.cxx }}+ run: python setup.py develop+ - name: Ensure ccache worked+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ run: |+ ccache --show-stats --verbose+ ccache --zero-stats+ cat ${{ runner.workspace }}/.ccache_log || true+ ls -lashR ${{ runner.workspace }}/pedalboard+ - name: Save Cached ${{ runner.os }} Objects+ id: cache-objects-save+ uses: actions/cache/save@v4+ with:+ path: |+ ${{ runner.workspace }}/.ccache+ ${{ runner.workspace }}/pedalboard/build/lib*+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/pedalboard/juce_overrides+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/vendors+ key: ${{ steps.cache-objects-restore.outputs.cache-primary-key }}+ - name: Archive Cached ${{ runner.os }} Objects+ uses: actions/upload-artifact@v4+ with:+ name: ${{ runner.os }}-ccache-${{ matrix.compiler }}-primed+ path: ${{ runner.workspace }}/.ccache_debug+ if-no-files-found: error+ retention-days: 1+ overwrite: true++ # Build the native module with ccache enabled so we can share object files between builds:+ prime-asan-build-caches:+ runs-on: ${{ matrix.os }}+ continue-on-error: false+ strategy:+ matrix:+ include:+ - { os: ubuntu-20.04, python-version: "3.12", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ name: Pre-build on ${{ matrix.os }} with ${{ matrix.compiler }}+ steps:+ - name: Set up Python ${{ matrix.python-version }}+ uses: actions/setup-python@v5+ with:+ python-version: ${{ matrix.python-version }}+ - uses: actions/checkout@v4+ with:+ submodules: recursive+ - name: Install Linux dependencies+ if: runner.os == 'Linux'+ run: |+ sudo apt-get update \+ && sudo apt-get install -y pkg-config libsndfile1 \+ libx11-dev libxrandr-dev libxinerama-dev \+ libxrender-dev libxcomposite-dev libxcb-xinerama0-dev \+ libxcursor-dev libfreetype6 libfreetype6-dev+ # We depend on ccache features that are only present in 4.8.0 and later, but installing from apt-get gives us v3.+ - name: Install ccache on Linux+ if: runner.os == 'Linux'+ run: |+ mkdir ccache+ curl -L https://github.com/ccache/ccache/releases/download/v4.9.1/ccache-4.9.1-linux-x86_64.tar.xz | tar xvJf - -C ccache+ mv ccache/ccache*/ccache /usr/local/bin/ccache+ chmod +x /usr/local/bin/ccache+ - name: Install ccache on macOS+ if: runner.os == 'macOS'+ run: brew install ccache+ - name: Install test dependencies+ env:+ # on macOS and with Python 3.10: building NumPy from source fails without these options:+ NPY_BLAS_ORDER: ""+ NPY_LAPACK_ORDER: ""+ run: |+ python -m pip install --upgrade pip+ pip install wheel+ pip install -r test-requirements.txt+ # TensorFlow is an optional dependency; if present, we'll run tests with it:+ # There are no environment specifiers to select when TensorFlow binaries are available.+ pip install tensorflow==2.13 || true+ - name: Restore Cached ${{ runner.os }} Objects+ id: cache-objects-restore+ uses: actions/cache/restore@v4+ with:+ path: ${{ runner.workspace }}/.ccache+ key: ${{ runner.os }}-${{ matrix.compiler }}-ccache+ - name: Build pedalboard locally+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ CCACHE_BASEDIR: ${{ runner.workspace }}+ CCACHE_DEBUGDIR: ${{ runner.workspace }}/.ccache_debug+ CCACHE_SLOPPINESS: "pch_defines,include_file_mtime,include_file_ctime,time_macros,locale,random_seed,system_headers"+ CCACHE_COMPILERCHECK: none+ CCACHE_NOINODECACHE: 1+ CCACHE_IGNOREOPTIONS: "-fno-strict-overflow -fwrapv -W* -arch x86_64 arm64 -dynamic -fno-common -g -I/usr/local/opt/*"+ CCACHE_LOGFILE: ${{ runner.workspace }}/.ccache_log+ USE_ASAN: "1"+ DISABLE_LTO: "1" # Speeds up un-cacheable link step which doesn't really increase performance in tests anyways+ CC: ${{ matrix.cc }}+ CXX: ${{ matrix.cxx }}+ run: python setup.py develop+ - name: Ensure ccache worked+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ run: |+ ccache --show-stats --verbose+ ccache --zero-stats+ cat ${{ runner.workspace }}/.ccache_log || true+ ls -lashR ${{ runner.workspace }}+ - name: Save Cached ${{ runner.os }} Objects+ id: cache-objects-save+ uses: actions/cache/save@v4+ with:+ path: |+ ${{ runner.workspace }}/.ccache+ ${{ runner.workspace }}/pedalboard/build/lib*+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/pedalboard/juce_overrides+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/vendors+ key: ${{ steps.cache-objects-restore.outputs.cache-primary-key }}++ # This initial job catches obvious failures faster by running tests in parallel on just Ubuntu.+ run-tests-in-parallel:+ runs-on: ${{ matrix.os }}+ continue-on-error: false+ needs:+ - prime-ubuntu-build-caches+ strategy:+ matrix:+ os: ["ubuntu-20.04"]+ python-version: ["3.12"]+ compiler: ["gcc"]+ cc: ["ccache gcc"]+ cxx: ["ccache g++"]+ runner_index: ["1", "2", "3", "4", "5", "6", "7", "8"]+ runner_total: ["8"]+ name: Test ${{ matrix.runner_index }} / ${{ matrix.runner_total }} with Python ${{ matrix.python-version }} on ${{ matrix.os }}+ steps:+ - name: Set up Python ${{ matrix.python-version }}+ uses: actions/setup-python@v5+ with:+ python-version: ${{ matrix.python-version }}+ - uses: actions/checkout@v4+ with:+ submodules: recursive+ - name: Install Linux dependencies+ if: runner.os == 'Linux'+ run: |+ sudo apt-get update \+ && sudo apt-get install -y pkg-config libsndfile1 \+ libx11-dev libxrandr-dev libxinerama-dev \+ libxrender-dev libxcomposite-dev libxcb-xinerama0-dev \+ libxcursor-dev libfreetype6 libfreetype6-dev+ # We depend on ccache features that are only present in 4.8.0 and later, but installing from apt-get gives us v3.+ - name: Install ccache on Linux+ if: runner.os == 'Linux'+ run: |+ mkdir ccache+ curl -L https://github.com/ccache/ccache/releases/download/v4.9.1/ccache-4.9.1-linux-x86_64.tar.xz | tar xvJf - -C ccache+ mv ccache/ccache*/ccache /usr/local/bin/ccache+ chmod +x /usr/local/bin/ccache+ - name: Install test dependencies+ env:+ # on macOS and with Python 3.10: building NumPy from source fails without these options:+ NPY_BLAS_ORDER: ""+ NPY_LAPACK_ORDER: ""+ run: |+ python -m pip install --upgrade pip+ pip install wheel+ pip install -r test-requirements.txt+ # TensorFlow is an optional dependency; if present, we'll run tests with it:+ # There are no environment specifiers to select when TensorFlow binaries are available.+ pip install tensorflow==2.13 || true+ - name: Restore Cached ${{ runner.os }} Objects+ id: cache-objects-restore+ uses: actions/cache/restore@v4+ with:+ path: |+ ${{ runner.workspace }}/.ccache+ ${{ runner.workspace }}/pedalboard/build/lib*+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/pedalboard/juce_overrides+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/vendors+ key: ${{ runner.os }}-${{ matrix.compiler }}-ccache+ - name: Print Restored ${{ runner.os }} Objects+ run: ls -lashR ${{ runner.workspace }}+ # Without this, distutils will recompile the extension even though we already have the .so built:+ - name: Touch Restored ${{ runner.os }} Objects to Prevent Cache Miss+ if: runner.os == 'Linux' || runner.os == 'macOS'+ run: |+ find ${{ runner.workspace }} -name '*.so' -exec touch {} \; || true+ find ${{ runner.workspace }} -name '*.o' -exec touch {} \; || true+ ls -lR ${{ runner.workspace }}/pedalboard+ - name: Build pedalboard locally+ run: python setup.py develop+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ CCACHE_BASEDIR: ${{ runner.workspace }}+ CCACHE_DEBUGDIR: ${{ runner.workspace }}/.ccache_debug+ CCACHE_SLOPPINESS: "pch_defines,include_file_mtime,include_file_ctime,time_macros,locale,random_seed,system_headers"+ CCACHE_COMPILERCHECK: none+ CCACHE_NOINODECACHE: 1+ CCACHE_IGNOREOPTIONS: "-fno-strict-overflow -fwrapv -W* -arch x86_64 arm64 -dynamic -fno-common -g -I/usr/local/opt/*"+ CCACHE_LOGFILE: ${{ runner.workspace }}/.ccache_log+ DISABLE_LTO: "1" # Speeds up un-cacheable link step which doesn't really increase performance in tests anyways+ CC: ${{ matrix.cc }}+ CXX: ${{ matrix.cxx }}+ - name: Ensure ccache worked+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ run: |+ ccache --show-stats --verbose+ ccache --zero-stats+ cat ${{ runner.workspace }}/.ccache_log || true+ ls -lashR ${{ runner.workspace }}+ - name: Install VSTs for testing+ env:+ GCS_ASSET_BUCKET_NAME: ${{ secrets.GCS_ASSET_BUCKET_NAME }}+ GCS_READER_SERVICE_ACCOUNT_KEY: ${{ secrets.GCS_READER_SERVICE_ACCOUNT_KEY }}+ run: python ./tests/download_test_plugins.py+ - name: Run tests+ env:+ TEST_WORKER_INDEX: ${{ matrix.runner_index }}+ NUM_TEST_WORKERS: ${{ matrix.runner_total }}+ run: pytest --maxfail=1 --durations=10+run-tests:runs-on: ${{ matrix.os }}continue-on-error: false+ needs:+ - prime-ubuntu-build-caches+ - prime-macos-build-cachesenv:MINIMUM_COVERAGE_PERCENTAGE: 80strategy:matrix:- python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']- os: ['ubuntu-20.04', windows-latest, macos-latest]+ include:+ - { os: macos-13, python-version: "3.7", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ - { os: macos-13, python-version: "3.8", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ - { os: macos-13, python-version: "3.9", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ - { os: macos-13, python-version: "3.10", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ - { os: macos-13, python-version: "3.11", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ - { os: macos-13, python-version: "3.12", compiler: "clang", cc: "ccache clang", cxx: "ccache clang++" }+ - { os: ubuntu-20.04, python-version: "3.7", compiler: "gcc", cc: "ccache gcc", cxx: "ccache g++" }+ - { os: ubuntu-20.04, python-version: "3.8", compiler: "gcc", cc: "ccache gcc", cxx: "ccache g++" }+ - { os: ubuntu-20.04, python-version: "3.9", compiler: "gcc", cc: "ccache gcc", cxx: "ccache g++" }+ - { os: ubuntu-20.04, python-version: "3.10", compiler: "gcc", cc: "ccache gcc", cxx: "ccache g++" }+ - { os: ubuntu-20.04, python-version: "3.11", compiler: "gcc", cc: "ccache gcc", cxx: "ccache g++" }+ - { os: ubuntu-20.04, python-version: "3.12", compiler: "gcc", cc: "ccache gcc", cxx: "ccache g++" }+ # No ccache for Windows, as it doesn't work with MSVC+ - { os: windows-latest, python-version: "3.7", compiler: "msvc", cc: "msvc", cxx: "msvc" }+ - { os: windows-latest, python-version: "3.8", compiler: "msvc", cc: "msvc", cxx: "msvc" }+ - { os: windows-latest, python-version: "3.9", compiler: "msvc", cc: "msvc", cxx: "msvc" }+ - { os: windows-latest, python-version: "3.10", compiler: "msvc", cc: "msvc", cxx: "msvc" }+ - { os: windows-latest, python-version: "3.11", compiler: "msvc", cc: "msvc", cxx: "msvc" }+ - { os: windows-latest, python-version: "3.12", compiler: "msvc", cc: "msvc", cxx: "msvc" }name: Test with Python ${{ matrix.python-version }} on ${{ matrix.os }}steps:- name: Set up Python ${{ matrix.python-version }}- uses: actions/setup-python@v2+ uses: actions/setup-python@v5with:python-version: ${{ matrix.python-version }}- - uses: actions/checkout@v2+ - uses: actions/checkout@v4with:submodules: recursive- name: Install Linux dependencies@@ -82,6 +456,17 @@ jobs:libx11-dev libxrandr-dev libxinerama-dev \libxrender-dev libxcomposite-dev libxcb-xinerama0-dev \libxcursor-dev libfreetype6 libfreetype6-dev+ # We depend on ccache features that are only present in 4.8.0 and later, but installing from apt-get gives us v3.+ - name: Install ccache on Linux+ if: runner.os == 'Linux'+ run: |+ mkdir ccache+ curl -L https://github.com/ccache/ccache/releases/download/v4.9.1/ccache-4.9.1-linux-x86_64.tar.xz | tar xvJf - -C ccache+ mv ccache/ccache*/ccache /usr/local/bin/ccache+ chmod +x /usr/local/bin/ccache+ - name: Install ccache on macOS+ if: runner.os == 'macOS'+ run: brew install ccache- name: Install test dependenciesenv:# on macOS and with Python 3.10: building NumPy from source fails without these options:@@ -105,8 +490,58 @@ jobs:uses: crazy-max/ghaction-chocolatey@v2with:args: install jq+ - name: Restore Cached ${{ runner.os }} Objects+ id: cache-objects-restore+ uses: actions/cache/restore@v4+ with:+ path: |+ ${{ runner.workspace }}/.ccache+ ${{ runner.workspace }}/pedalboard/build/lib*+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/pedalboard/juce_overrides+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/vendors+ key: ${{ runner.os }}-${{ matrix.compiler }}-ccache+ # Without this, distutils will recompile the extension even though we already have the shared object built:+ - name: Touch Restored ${{ runner.os }} Objects to Prevent Cache Miss+ if: runner.os == 'Linux' || runner.os == 'macOS'+ run: |+ find ${{ runner.workspace }} -name '*.so' -exec touch {} \; || true+ find ${{ runner.workspace }} -name '*.o' -exec touch {} \; || true+ ls -lR ${{ runner.workspace }}/pedalboard- name: Build pedalboard locallyrun: python setup.py develop+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ CCACHE_BASEDIR: ${{ runner.workspace }}+ CCACHE_DEBUGDIR: ${{ runner.workspace }}/.ccache_debug+ CCACHE_SLOPPINESS: "pch_defines,include_file_mtime,include_file_ctime,time_macros,locale,random_seed,system_headers"+ CCACHE_COMPILERCHECK: none+ CCACHE_NOINODECACHE: 1+ CCACHE_IGNOREOPTIONS: "-fno-strict-overflow -fwrapv -W* -arch x86_64 arm64 -dynamic -fno-common -g -I/usr/local/opt/*"+ CCACHE_LOGFILE: ${{ runner.workspace }}/.ccache_log+ CCACHE_DEBUG: "1"+ MACOSX_DEPLOYMENT_TARGET: "10.13"+ # This build caching is only to speed up tests on CI, so we only care about x86_64 for now.+ # Without limiting to a single architecture, ccache can't properly cache mixed Objective-C and C++ builds.+ # Fun fact: this is supported in Python itself! https://github.com/python/cpython/blob/893c9cc/Lib/_osx_support.py#L314-L328+ ARCHFLAGS: -arch x86_64+ DISABLE_LTO: "1" # Speeds up un-cacheable link step which doesn't really increase performance in tests anyways+ CC: ${{ matrix.cc }}+ CXX: ${{ matrix.cxx }}+ - name: Ensure ccache worked+ if: runner.os == 'Linux' || runner.os == 'macOS'+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ run: |+ ccache --show-stats --verbose+ ccache --zero-stats+ cat ${{ runner.workspace }}/.ccache_log || true+ - name: Archive Cached ${{ runner.os }} Objects+ uses: actions/upload-artifact@v4+ with:+ name: ${{ runner.os }}-${{ matrix.python-version }}-ccache-${{ matrix.compiler }}-runtime+ path: ${{ runner.workspace }}/.ccache_debug+ retention-days: 1+ overwrite: true- name: Install VSTs for testingenv:GCS_ASSET_BUCKET_NAME: ${{ secrets.GCS_ASSET_BUCKET_NAME }}@@ -114,11 +549,11 @@ jobs:run: python ./tests/download_test_plugins.py- name: Run testsif: matrix.os != 'ubuntu-20.04' || matrix.python-version != '3.8'- run: pytest -v --cov-report term --cov-fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} --cov=pedalboard --durations=100+ run: pytest --maxfail=4 --cov-report term --cov-fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} --cov=pedalboard --durations=100- name: Run tests with coverage reportingif: matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'run: |- pytest -v --cov-report term --cov-fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} --cov=pedalboard \+ pytest --maxfail=4 --cov-report term --cov-fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} --cov=pedalboard \&& coverage json --fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} \&& jq -r 'def roundit: .*100.0 + 0.5|floor/100.0; .totals.percent_covered | round | "COVERAGE_PERCENTAGE=" + (. | tostring) + "%" ' coverage.json >> $GITHUB_ENV \&& jq -r 'if .totals.percent_covered > ${{ env.MINIMUM_COVERAGE_PERCENTAGE }} then "COVERAGE_COLOR=green" else "COVERAGE_COLOR=red" end' coverage.json >> $GITHUB_ENV@@ -135,6 +570,7 @@ jobs:run-tests-with-address-sanitizer:runs-on: ${{ matrix.os }}+ needs: [prime-asan-build-caches]strategy:matrix:python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']@@ -142,10 +578,10 @@ jobs:name: Test with Python ${{ matrix.python-version }} + Address Sanitizersteps:- name: Set up Python ${{ matrix.python-version }}- uses: actions/setup-python@v2+ uses: actions/setup-python@v5with:python-version: ${{ matrix.python-version }}- - uses: actions/checkout@v2+ - uses: actions/checkout@v4with:submodules: recursive- name: Install Linux dependencies@@ -156,6 +592,14 @@ jobs:libx11-dev libxrandr-dev libxinerama-dev \libxrender-dev libxcomposite-dev libxcb-xinerama0-dev \libxcursor-dev libfreetype6 libfreetype6-dev+ # We depend on ccache features that are only present in 4.8.0 and later, but installing from apt-get gives us v3.+ - name: Install ccache on Linux+ if: runner.os == 'Linux'+ run: |+ mkdir ccache+ curl -L https://github.com/ccache/ccache/releases/download/v4.9.1/ccache-4.9.1-linux-x86_64.tar.xz | tar xvJf - -C ccache+ mv ccache/ccache*/ccache /usr/local/bin/ccache+ chmod +x /usr/local/bin/ccache- name: Install test dependenciesrun: |python -m pip install --upgrade pip@@ -164,13 +608,40 @@ jobs:# TensorFlow is an optional dependency; if present, we'll run tests with it:# There are no environment specifiers to select when TensorFlow binaries are available.pip install tensorflow==2.13 || true+ - name: Restore Cached ${{ runner.os }} Objects+ id: cache-objects-restore+ uses: actions/cache/restore@v4+ with:+ path: |+ ${{ runner.workspace }}/.ccache+ ${{ runner.workspace }}/pedalboard/build/lib*+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/pedalboard/juce_overrides+ ${{ runner.workspace }}/pedalboard/build/temp${{ runner.workspace }}/pedalboard/vendors+ key: ${{ runner.os }}-clang-ccache- name: Build pedalboard locallyenv:DEBUG: "0"USE_ASAN: "1"- CC: clang- CXX: clang+++ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ CCACHE_BASEDIR: ${{ runner.workspace }}+ CCACHE_DEBUGDIR: ${{ runner.workspace }}/.ccache_debug+ CCACHE_SLOPPINESS: "pch_defines,include_file_mtime,include_file_ctime,time_macros,locale,random_seed,system_headers"+ CCACHE_COMPILERCHECK: none+ CCACHE_NOINODECACHE: 1+ CCACHE_IGNOREOPTIONS: "-fno-strict-overflow -fwrapv -W* -arch x86_64 arm64 -dynamic -fno-common -g -I/usr/local/opt/*"+ CCACHE_LOGFILE: ${{ runner.workspace }}/.ccache_log+ CCACHE_DEBUG: "1"+ DISABLE_LTO: "1" # Speeds up un-cacheable link step which doesn't really increase performance in tests anyways+ CC: ccache clang+ CXX: ccache clang++run: python setup.py develop+ - name: Ensure ccache worked+ env:+ CCACHE_DIR: ${{ runner.workspace }}/.ccache+ run: |+ ccache --show-stats --verbose+ ccache --zero-stats+ cat ${{ runner.workspace }}/.ccache_log || true- name: Run tests with ASan loaded# pytest can exit before all Python objects have been destroyed,# so we tell ASan to ignore leaks.@@ -249,11 +720,11 @@ jobs:- { os: 'ubuntu-20.04', build: pp39-manylinux_aarch64 }name: Build wheel for ${{ matrix.build }}steps:- - uses: actions/checkout@v2+ - uses: actions/checkout@v4with:submodules: recursive# Used to host cibuildwheel, so version doesn't really matter- - uses: actions/setup-python@v2+ - uses: actions/setup-python@v5with:python-version: "3.10"- name: Install cibuildwheeldiff --git a/.gitmodules b/.gitmodulesindex eba99dc..589e6c1 100644--- a/.gitmodules+++ b/.gitmodules@@ -10,3 +10,6 @@[submodule "vendors/libgsm"]path = vendors/libgsmurl = https://github.com/timothytylee/libgsm.git+[submodule "vendors/pybind11"]+ path = vendors/pybind11+ url = [email protected]:pybind/pybind11.gitdiff --git a/docs-requirements.txt b/docs-requirements.txtindex 5df18cb..19c0aa7 100644--- a/docs-requirements.txt+++ b/docs-requirements.txt@@ -1,2 +1,12 @@+-r test-requirements.txt+mkdocs==1.0.4-interrogate+pybind11-stubgen==0.11.0+mypy+# For documentation:+sphinx==5.3.0; python_version > '3.6'+sphinx-copybutton==0.5.1; python_version > '3.6'+docutils==0.19; python_version > '3.6'+m2r2==0.3.3; python_version > '3.6'+furo==2022.9.29; python_version > '3.6'+sphinxext-opengraph==0.7.3; python_version > '3.6'diff --git a/pedalboard/ExternalPlugin.h b/pedalboard/ExternalPlugin.hindex c56eb4e..47364e5 100644--- a/pedalboard/ExternalPlugin.h+++ b/pedalboard/ExternalPlugin.h@@ -385,37 +385,45 @@ public:return;}- JUCE_AUTORELEASEPOOL {- StandalonePluginWindow window(processor);- window.show();-- // Run in a tight loop so that we don't have to call ->stopDispatchLoop(),- // which causes the MessageManager to become unusable in the future.- // The window can be closed by sending a KeyboardInterrupt, closing- // the window in the UI, or setting the provided Event object.- while (window.isVisible()) {- bool errorThrown = PyErr_CheckSignals() != 0;- bool eventSet = optionalEvent != py::none() &&- optionalEvent.attr("is_set")().cast<bool>();-- if (errorThrown || eventSet) {- window.closeButtonPressed();- shouldThrowErrorAlreadySet = errorThrown;- break;- }+ {+ // Release the GIL to allow other Python threads to run in the+ // background while we the UI is running:+ py::gil_scoped_release release;+ JUCE_AUTORELEASEPOOL {+ StandalonePluginWindow window(processor);+ window.show();++ // Run in a tight loop so that we don't have to call+ // ->stopDispatchLoop(), which causes the MessageManager to become+ // unusable in the future. The window can be closed by sending a+ // KeyboardInterrupt, closing the window in the UI, or setting the+ // provided Event object.+ while (window.isVisible()) {+ bool errorThrown = false;+ bool eventSet = false;++ {+ py::gil_scoped_acquire acquire;++ errorThrown = PyErr_CheckSignals() != 0;+ eventSet = optionalEvent != py::none() &&+ optionalEvent.attr("is_set")().cast<bool>();+ }++ if (errorThrown || eventSet) {+ window.closeButtonPressed();+ shouldThrowErrorAlreadySet = errorThrown;+ break;+ }- {- // Release the GIL to allow other Python threads to run in the- // background while we the UI is running:- py::gil_scoped_release release;juce::MessageManager::getInstance()->runDispatchLoopUntil(10);}}- }- // Once the Autorelease pool has been drained, pump the dispatch loop one- // more time to process any window close events:- juce::MessageManager::getInstance()->runDispatchLoopUntil(10);+ // Once the Autorelease pool has been drained, pump the dispatch loop one+ // more time to process any window close events:+ juce::MessageManager::getInstance()->runDispatchLoopUntil(10);+ }if (shouldThrowErrorAlreadySet) {throw py::error_already_set();@@ -1279,16 +1287,6 @@ public:"Pedalboard error and should be reported.");}- if (!juce::Desktop::getInstance().getDisplays().getPrimaryDisplay()) {- throw std::runtime_error(- "Editor cannot be shown - no visual display devices available.");- }-- if (!juce::MessageManager::getInstance()->isThisTheMessageThread()) {- throw std::runtime_error(- "Plugin UI windows can only be shown from the main thread.");- }-if (optionalEvent != py::none() && !py::hasattr(optionalEvent, "is_set")) {throw py::type_error("Pedalboard expected a threading.Event object to be "@@ -1297,6 +1295,19 @@ public:"\") does not have an 'is_set' method.");}+ {+ py::gil_scoped_release release;+ if (!juce::Desktop::getInstance().getDisplays().getPrimaryDisplay()) {+ throw std::runtime_error(+ "Editor cannot be shown - no visual display devices available.");+ }++ if (!juce::MessageManager::getInstance()->isThisTheMessageThread()) {+ throw std::runtime_error(+ "Plugin UI windows can only be shown from the main thread.");+ }+ }+StandalonePluginWindow::openWindowAndWait(*pluginInstance, optionalEvent);}diff --git a/pedalboard/_pedalboard.py b/pedalboard/_pedalboard.pyindex a7da2e1..91c0a87 100644--- a/pedalboard/_pedalboard.py+++ b/pedalboard/_pedalboard.py@@ -70,9 +70,28 @@ class Pedalboard(Chain):)-FLOAT_SUFFIXES_TO_IGNORE: Set[str] = set(- ["x", "%", "*", ",", ".", "hz", "ms", "sec", "seconds", "dB", "dBTP"]-)+# Stored in a trie to speed up these matches, as they happen millions of times in test:+FLOAT_SUFFIXES_TO_IGNORE = ["x", "%", "*", ",", ".", "hz", "ms", "db", "sec", "dbtp", "seconds"]+++class _SuffixTrie:+ def __init__(self, char: Optional[str]):+ self.char = char+ self.children: Dict[str, Optional["_SuffixTrie"]] = {}+ self.is_match = False++ def __repr__(self) -> str:+ return f"<_SuffixTrie {self.char} {self.is_match} {self.children}>"+++FLOAT_SUFFIX_TRIE = _SuffixTrie("")+for suffix in FLOAT_SUFFIXES_TO_IGNORE:+ node = FLOAT_SUFFIX_TRIE+ for char in suffix[::-1]:+ if char not in node.children:+ node.children[char] = _SuffixTrie(char)+ node = cast(_SuffixTrie, node.children[char])+ node.is_match = Truedef strip_common_float_suffixes(@@ -82,21 +101,29 @@ def strip_common_float_suffixes(return ss = s.strip()+ s_lower = s.lower()# Handle certain plugins that report "Hz" and "kHz" suffixes:- if strip_si_prefixes:- if s.lower().endswith("khz") and len(s) > 3:- try:- s = str(float(s[:-3]) * 1000)- except ValueError:- pass-- for suffix in FLOAT_SUFFIXES_TO_IGNORE:- if suffix == "hz" and "khz" in s.lower():- continue- if s[-len(suffix) :].lower() == suffix.lower():- s = s[: -len(suffix)].strip()- return s+ if strip_si_prefixes and s_lower.endswith("khz") and len(s) >= 3:+ try:+ return str(float(s[:-3]) * 1000)+ except ValueError:+ return s++ while True:+ node = FLOAT_SUFFIX_TRIE+ for i in reversed(range(len(s_lower))):+ char = s_lower[i]+ if char in node.children:+ node = cast(_SuffixTrie, node.children[char])+ if node.is_match:+ s = s[:i].strip()+ s_lower = s_lower[: len(s)]+ break+ else:+ return s+ else:+ return sdef looks_like_float(s: Union[float, str]) -> bool:diff --git a/setup.py b/setup.pyindex ecbaf23..79bf9dd 100644--- a/setup.py+++ b/setup.py@@ -14,14 +14,15 @@# See the License for the specific language governing permissions and# limitations under the License.-+import loggingimport osimport platform-from subprocess import check_output-from pybind11.setup_helpers import Pybind11Extension, build_ext-from pathlib import Pathfrom distutils.core import setupfrom distutils.unixccompiler import UnixCCompiler+from pathlib import Path+from subprocess import check_output++from pybind11.setup_helpers import Pybind11Extension, build_extDEBUG = bool(int(os.environ.get("DEBUG", 0)))@@ -72,13 +73,19 @@ ALL_CPPFLAGS.extend("-DJUCE_DISABLE_JUCE_VERSION_PRINTING=1","-DJUCE_WEB_BROWSER=0","-DJUCE_USE_CURL=0",- "-DJUCE_USE_MP3AUDIOFORMAT=1",+ "-DJUCE_USE_MP3AUDIOFORMAT=0", # We've patched this out too"-DJUCE_USE_FLAC=0", # We've patched this out# "-DJUCE_USE_FREETYPE=0","-DJUCE_MODAL_LOOPS_PERMITTED=1",])-ALL_INCLUDES.extend(["JUCE/modules/", "JUCE/modules/juce_audio_processors/format_types/VST3_SDK/"])+ALL_INCLUDES.extend(+ [+ "vendors/pybind11/include/",+ "JUCE/modules/",+ "JUCE/modules/juce_audio_processors/format_types/VST3_SDK/",+ ]+)if "musllinux" in os.getenv("CIBW_BUILD", ""):# For Alpine/musllinux compatibility:@@ -130,7 +137,7 @@ ALL_INCLUDES += ["vendors/libgsm/inc"]if platform.system() == "Darwin":ALL_CPPFLAGS.append("-DMACOS=1")ALL_CPPFLAGS.append("-DHAVE_VDSP=1")- if not DEBUG:+ if not DEBUG and not os.getenv("DISABLE_LTO"):ALL_CPPFLAGS.append("-flto=thin")ALL_LINK_ARGS.append("-flto=thin")ALL_LINK_ARGS.append("-fvisibility=hidden")@@ -138,7 +145,7 @@ if platform.system() == "Darwin":elif platform.system() == "Linux":ALL_CPPFLAGS.append("-DLINUX=1")# We use GCC on Linux, which doesn't take a value for the -flto flag:- if not DEBUG:+ if not DEBUG and not os.getenv("DISABLE_LTO"):ALL_CPPFLAGS.append("-flto")ALL_LINK_ARGS.append("-flto")ALL_LINK_ARGS.append("-fvisibility=hidden")@@ -271,6 +278,16 @@ def patch_compile(original_compile):extra_postargs = [arg for arg in extra_postargs if "std=" not in arg]_cc_args = cc_args + ALL_CFLAGS+ # Code in JUCE or vendors should not even know we're using Python:+ should_omit_python_header = any(x in src for x in ("JUCE", "/juce_overrides/", "/vendors/"))++ # Remove the Python header from most files; we only need it when compiling+ # This speeds up compile times on CI as most of the objects don't need Python+ # headers at all, and including -I/include/python3.x/Python.h prevents us from+ # re-using the same object file for different Python versions.+ if any("include/python3" in arg for arg in _cc_args) and should_omit_python_header:+ _cc_args = [arg for arg in _cc_args if "include/python3" not in arg]+return original_compile(obj, src, ext, _cc_args, extra_postargs, *args, **kwargs)return new_compile@@ -281,6 +298,13 @@ class BuildC_CxxExtensions(build_ext):Add custom logic for injecting different arguments when compiling C vs C++ files."""+ def initialize_options(self):+ build_ext.initialize_options(self)+ # If on CI, avoid breaking ccache by using a consistent+ # output directory name regardless of Python version:+ if os.getenv("CI"):+ self.build_temp = "./build/temp"+def build_extensions(self, *args, **kwargs):self.compiler._compile = patch_compile(self.compiler._compile)build_ext.build_extensions(self, *args, **kwargs)@@ -302,6 +326,7 @@ pedalboard_cpp = Pybind11Extension(libraries=ALL_LIBRARIES,language="c++",cxx_std=17,+ include_pybind11=False,)@@ -318,6 +343,8 @@ version = {}version_file_contents = (this_directory / "pedalboard" / "version.py").read_text()exec(version_file_contents, version)+logging.basicConfig(format="%(message)s")+setup(name="pedalboard",version=version["__version__"],diff --git a/test-requirements.txt b/test-requirements.txtindex 6d1e425..71d03dc 100644--- a/test-requirements.txt+++ b/test-requirements.txt@@ -7,26 +7,13 @@ setuptools>=59pip>22; python_version > '3.6'pip>21; python_version < '3.7'wheel-flake8-black==22.6.0-click==8.0.4-interrogatenumpygoogle-cloud-storagetqdmpsutil-pybind11-stubgen==0.11.0mypy-# For documentation:-sphinx==5.3.0; python_version > '3.6'-sphinx-copybutton==0.5.1; python_version > '3.6'-docutils==0.19; python_version > '3.6'-m2r2==0.3.3; python_version > '3.6'-furo==2022.9.29; python_version > '3.6'-sphinxext-opengraph==0.7.3; python_version > '3.6'-# For MIDI support - only in test though!midomutagen\ No newline at end of filediff --git a/tests/conftest.py b/tests/conftest.pynew file mode 100644index 0000000..5ab100e--- /dev/null+++ b/tests/conftest.py@@ -0,0 +1,19 @@+import os+++def pytest_collection_modifyitems(session, config, items):+ """+ Allow for parallel test execution on GitHub Actions without third-party plugins.+ """+ num_test_workers = int(os.getenv("NUM_TEST_WORKERS", "1"))+ test_worker_index = int(os.getenv("TEST_WORKER_INDEX", "1")) - 1+ if num_test_workers == 1:+ return+ print(f"\n\nRunning tests for worker {test_worker_index + 1} of {num_test_workers}.")+ print(+ f"This process will only run one out of every {num_test_workers:,}"+ f" tests, offset by {test_worker_index}.\n"+ )+ for i, item in enumerate(list(items)):+ if (i + test_worker_index) % num_test_workers != 0:+ items.remove(item)diff --git a/tests/test_audio_stream.py b/tests/test_audio_stream.pyindex ac455a1..1ffe90a 100644--- a/tests/test_audio_stream.py+++ b/tests/test_audio_stream.py@@ -15,11 +15,11 @@# limitations under the License.-import time-import pytestimport platform-import pedalboard+import pytest++import pedalboard# Very silly: even just creating an AudioStream object that reads from an `iPhone Microphone``# will cause a locally-present iPhone to emit a sound. Running `pytest` on my laptop makes my@@ -59,11 +59,9 @@ def test_create_stream(input_device_name: str, output_device_name: str):# Ensure that modifying a running stream does not crash:stream.plugins.append(pedalboard.Gain(gain_db=-120))- for _ in range(0, 100):- time.sleep(0.01)+ for _ in range(0, 10):stream.plugins.append(pedalboard.Gain(gain_db=-120))for i in reversed(range(len(stream.plugins))):- time.sleep(0.01)del stream.plugins[i]assert stream.runningassert not stream.runningdiff --git a/tests/test_bitcrush.py b/tests/test_bitcrush.pyindex d3674f6..bad69ff 100644--- a/tests/test_bitcrush.py+++ b/tests/test_bitcrush.py@@ -15,15 +15,17 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard import Bitcrush+from .utils import generate_sine_at@pytest.mark.parametrize("bit_depth", list(np.arange(1, 32, 0.5)))[email protected]("fundamental_hz", [440, 880])[email protected]("sample_rate", [22050, 44100, 48000])[email protected]("fundamental_hz", [440])[email protected]("sample_rate", [22050, 48000])@pytest.mark.parametrize("num_channels", [1, 2])def test_bitcrush(bit_depth: float, fundamental_hz: float, sample_rate: float, num_channels: int):sine_wave = generate_sine_at(diff --git a/tests/test_clipping.py b/tests/test_clipping.pyindex 0e0d5ad..c3c9c27 100644--- a/tests/test_clipping.py+++ b/tests/test_clipping.py@@ -15,17 +15,19 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard import Clipping-from .utils import generate_sine_at, db_to_gain++from .utils import db_to_gain, generate_sine_at@pytest.mark.parametrize("threshold_db", list(np.arange(0.0, -40, -0.5)))[email protected]("fundamental_hz", [440, 880])[email protected]("sample_rate", [22050, 44100, 48000])[email protected]("fundamental_hz", [440])[email protected]("sample_rate", [22050, 48000])@pytest.mark.parametrize("num_channels", [1, 2])-def test_bitcrush(+def test_clipping(threshold_db: float, fundamental_hz: float, sample_rate: float, num_channels: int):sine_wave = generate_sine_at(diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.pyindex 05a3988..3118e8c 100644--- a/tests/test_external_plugins.py+++ b/tests/test_external_plugins.py@@ -21,6 +21,7 @@ import osimport platformimport randomimport shutil+import signalimport subprocessimport threadingimport time@@ -81,6 +82,28 @@ AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT = (AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT + AVAILABLE_INSTRUMENT_PLUGINS_IN_TEST_ENVIRONMENT)+ONE_AVAILABLE_TEST_PLUGIN = (+ [AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT[0]] if AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT else []+)++ONE_AVAILABLE_INSTRUMENT_PLUGIN = (+ [AVAILABLE_INSTRUMENT_PLUGINS_IN_TEST_ENVIRONMENT[0]]+ if AVAILABLE_INSTRUMENT_PLUGINS_IN_TEST_ENVIRONMENT+ else []+)+++def sample(collection, number: int):+ """+ A tiny wrapper around random.sample() that supports empty collections+ and collections that are smaller than the desired sample size.+ """+ if not collection:+ return []+ if len(collection) <= number:+ return collection+ return random.sample(collection, number)+def is_container_plugin(filename: str):for klass in pedalboard._AVAILABLE_PLUGIN_CLASSES:@@ -282,11 +305,17 @@ def test_preset_parameters(plugin_filename: str, plugin_preset: str):@pytest.mark.parametrize("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)def test_initial_parameters(plugin_filename: str):parameters = {- k: v.min_value for k, v in get_parameters(plugin_filename).items() if v.type == float+ # Using max_value here avoids setting parameters like "volume"+ # or "gain" to 0, which slows down the re-initialization of a plugin.+ k: (v.max_value if k == "gain" else v.min_value)+ for k, v in get_parameters(plugin_filename).items()+ if v.type == float}# Reload the plugin, but set the initial parameters in the load call.- plugin = load_test_plugin(plugin_filename, parameter_values=parameters)+ plugin = load_test_plugin(+ plugin_filename, parameter_values=parameters, initialization_timeout=1.0+ )for name, expected in parameters.items():actual = getattr(plugin, name)@@ -297,11 +326,14 @@ def test_initial_parameters(plugin_filename: str):@pytest.mark.parametrize("plugin_filename,parameter_name",- [- (path, parameter)- for path in AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT- for parameter in [k for k, v in get_parameters(path).items() if v.type == float]- ],+ sample(+ [+ (path, parameter)+ for path in AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT+ for parameter in [k for k, v in get_parameters(path).items() if v.type == float]+ ],+ 5,+ ),)def test_initial_parameter_validation(plugin_filename: str, parameter_name: str):plugin = load_test_plugin(plugin_filename)@@ -324,7 +356,7 @@ def test_import_error_on_missing_path(loader):loader("./")[email protected]("plugin_filename", AVAILABLE_INSTRUMENT_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", ONE_AVAILABLE_INSTRUMENT_PLUGIN)@pytest.mark.parametrize("num_channels,sample_rate", [(2, 48000), (2, 44100), (2, 22050)])@pytest.mark.parametrize("notes",@@ -397,28 +429,28 @@ def test_effect_plugin_does_not_accept_notes(plugin(notes, 6.0, sample_rate, num_channels=num_channels)[email protected]("plugin_filename", AVAILABLE_INSTRUMENT_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", ONE_AVAILABLE_INSTRUMENT_PLUGIN)@pytest.mark.parametrize("num_channels,sample_rate", [(2, 48000), (2, 44100), (2, 22050)])def test_instrument_plugin_accepts_buffer_size(plugin_filename: str, num_channels: int, sample_rate: float):notes = [mido.Message("note_on", note=100, velocity=3, time=0),- mido.Message("note_off", note=100, time=5.0),+ mido.Message("note_off", note=100, time=0.5),]plugin = load_test_plugin(plugin_filename)assert plugin.is_instrumentassert not plugin.is_effectoutputs = [- plugin(notes, 6.0, sample_rate, num_channels=num_channels, buffer_size=buffer_size)+ plugin(notes, 1.0, sample_rate, num_channels=num_channels, buffer_size=buffer_size)for buffer_size in [1, 32, 1024]]for a, b in zip(outputs, outputs[1:]):np.testing.assert_allclose(a, b, atol=0.02)[email protected]("plugin_filename", AVAILABLE_INSTRUMENT_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", ONE_AVAILABLE_INSTRUMENT_PLUGIN)@pytest.mark.parametrize("num_channels,sample_rate", [(2, 48000), (2, 44100), (2, 22050)])def test_instrument_plugin_does_not_accept_audio(plugin_filename: str, num_channels: int, sample_rate: float@@ -521,11 +553,14 @@ def test_attributes_proxy(plugin_filename: str):@pytest.mark.parametrize("plugin_filename,parameter_name",- [- (path, parameter)- for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT- for parameter in [k for k, v in get_parameters(path).items() if v.type == bool]- ],+ sample(+ [+ (path, parameter)+ for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT+ for parameter in [k for k, v in get_parameters(path).items() if v.type == bool]+ ],+ 5,+ ),)def test_bool_parameters(plugin_filename: str, parameter_name: str):plugin = load_test_plugin(plugin_filename)@@ -546,11 +581,14 @@ def test_bool_parameters(plugin_filename: str, parameter_name: str):@pytest.mark.parametrize("plugin_filename,parameter_name",- [- (path, parameter)- for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT- for parameter in [k for k, v in get_parameters(path).items() if v.type == bool]- ],+ sample(+ [+ (path, parameter)+ for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT+ for parameter in [k for k, v in get_parameters(path).items() if v.type == bool]+ ],+ 5,+ ),)def test_bool_parameter_valdation(plugin_filename: str, parameter_name: str):plugin = load_test_plugin(plugin_filename)@@ -560,11 +598,14 @@ def test_bool_parameter_valdation(plugin_filename: str, parameter_name: str):@pytest.mark.parametrize("plugin_filename,parameter_name",- [- (path, parameter)- for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT- for parameter in [k for k, v in get_parameters(path).items() if v.type == float]- ],+ sample(+ [+ (path, parameter)+ for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT+ for parameter in [k for k, v in get_parameters(path).items() if v.type == float]+ ],+ 5,+ ),)def test_float_parameters(plugin_filename: str, parameter_name: str):plugin = load_test_plugin(plugin_filename)@@ -599,11 +640,14 @@ def test_float_parameters(plugin_filename: str, parameter_name: str):@pytest.mark.parametrize("plugin_filename,parameter_name",- [- (path, parameter)- for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT- for parameter in [k for k, v in get_parameters(path).items() if v.type == float]- ],+ sample(+ [+ (path, parameter)+ for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT+ for parameter in [k for k, v in get_parameters(path).items() if v.type == float]+ ],+ 5,+ ),)def test_float_parameter_valdation(plugin_filename: str, parameter_name: str):plugin = load_test_plugin(plugin_filename)@@ -633,11 +677,14 @@ def test_float_parameter_valdation(plugin_filename: str, parameter_name: str):@pytest.mark.parametrize("plugin_filename,parameter_name",- [- (path, parameter)- for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT- for parameter in [k for k, v in get_parameters(path).items() if v.type == str]- ],+ sample(+ [+ (path, parameter)+ for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT+ for parameter in [k for k, v in get_parameters(path).items() if v.type == str]+ ],+ 5,+ ),)def test_str_parameters(plugin_filename: str, parameter_name: str):plugin = load_test_plugin(plugin_filename)@@ -658,11 +705,14 @@ def test_str_parameters(plugin_filename: str, parameter_name: str):@pytest.mark.parametrize("plugin_filename,parameter_name",- [- (path, parameter)- for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT- for parameter in [k for k, v in get_parameters(path).items() if v.type == str]- ],+ sample(+ [+ (path, parameter)+ for path in AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT+ for parameter in [k for k, v in get_parameters(path).items() if v.type == str]+ ],+ 5,+ ),)def test_string_parameter_valdation(plugin_filename: str, parameter_name: str):plugin = load_test_plugin(plugin_filename)@@ -675,7 +725,7 @@ def test_string_parameter_valdation(plugin_filename: str, parameter_name: str):setattr(plugin, parameter_name, "some value not present")[email protected]("plugin_filename", AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", sample(AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT, 1))def test_plugin_parameters_persist_between_calls(plugin_filename: str):plugin = load_test_plugin(plugin_filename)sr = 44100@@ -723,7 +773,7 @@ def test_plugin_parameters_persist_between_calls(plugin_filename: str):), f"Expected {name} to match saved value"[email protected]("plugin_filename", AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", sample(AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT, 1))def test_plugin_state_cleared_between_invocations_by_default(plugin_filename: str):plugin = load_test_plugin(plugin_filename, disable_caching=True)@@ -845,8 +895,8 @@ def test_parameter_name_normalization(_input: str, expected: str):@pytest.mark.skipif(not plugin_named("CHOWTapeModel"), reason="Missing CHOWTapeModel plugin.")[email protected]("buffer_size", [16, 128, 8192, 65536])[email protected]("oversampling", [1, 2, 4, 8, 16])[email protected]("buffer_size", [16, 65536])[email protected]("oversampling", [1, 16])def test_external_plugin_latency_compensation(buffer_size: int, oversampling: int):"""This test loads CHOWTapeModel (which has non-zero latency due@@ -865,52 +915,114 @@ def test_external_plugin_latency_compensation(buffer_size: int, oversampling: innp.testing.assert_allclose(output, noise, atol=0.05)[email protected]("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)[email protected](platform.system() == "Windows", reason="Windows subprocess handling")[email protected]("plugin_filename", ONE_AVAILABLE_TEST_PLUGIN)def test_show_editor(plugin_filename: str):# Run this test in a subprocess, as otherwise we'd block this thread:full_plugin_filename = find_plugin_path(plugin_filename)try:- subprocess.check_output(- [- psutil.Process(os.getpid()).exe(),- "-c",- "import pedalboard;"- f'pedalboard.load_plugin(r"{full_plugin_filename}").show_editor();',- ],- timeout=5,+ command = [+ psutil.Process(os.getpid()).exe(),+ "-c",+ f"""+import sys+import pedalboard+try:+ plugin = pedalboard.load_plugin(r"{full_plugin_filename}")+ sys.stdout.write("OK")+ sys.stdout.flush()+ plugin.show_editor()+except KeyboardInterrupt:+ raise SystemExit(0)+""",+ ]+ process = subprocess.Popen(+ command,+ stdin=subprocess.DEVNULL,+ stdout=subprocess.PIPE,stderr=subprocess.STDOUT,)- except subprocess.CalledProcessError as e:+ try:+ stdout = process.stdout.read(2) # Wait for the "OK" message to be printed.+ if stdout != b"OK":+ return_code = process.wait(timeout=1)+ process.kill()+ stdout += process.stdout.read()+ raise RuntimeError(+ f"Command {command!r} failed with {return_code}. Stdout was: {stdout!r}"+ )++ # Send a KeyboardInterrupt into the process, which should kill the editor:+ process.send_signal(signal.SIGINT)++ return_code = process.wait(timeout=4)+ stdout = process.stdout.read()+ if return_code != 0:+ raise RuntimeError(+ f"Command {command!r} failed with {return_code}. Stdout was: {stdout!r}"+ )+ finally:+ try:+ if process.poll() is not None:+ process.kill()+ except Exception:+ pass+ except RuntimeError:if (- b"no visual display devices available" in e.output+ b"no visual display devices available" in stdout# Unsure why, but in some test environments, we# can't load Pedalboard in a subprocess.# TODO(psobot): Ensure we can load Pedalboard properly# in all environments for this test.- or b"No module named 'pedalboard'" in e.output+ or b"No module named 'pedalboard'" in stdout):passelse:raise- except subprocess.TimeoutExpired:- # This is good: the UI was shown, no issues.- pass[email protected]("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("delay", [0.0, 0.5, 1.0])-def test_show_editor_in_process(plugin_filename: str, delay: float):+class Watchdog(threading.Thread):+ """+ These show_editor tests time out on CI quite frequently.+ This watchdog should catch that for us.+ """++ def __init__(self, timeout_seconds: float = 10.0):+ super().__init__(daemon=True)+ self.daemon = True+ self.timeout_seconds = timeout_seconds+ self.cancelled = False++ def __enter__(self):+ self.start()++ def __exit__(self, *args, **kwargs):+ self.cancelled = True++ def run(self):+ time.sleep(self.timeout_seconds)+ if not self.cancelled:+ print(f"Watchdog timed out after {self.timeout_seconds:.2f} seconds!")+ os._exit(1)++[email protected]("plugin_filename", ONE_AVAILABLE_TEST_PLUGIN)[email protected]("timeout", [0.0, 0.25, 0.5])+def test_show_editor_in_process(plugin_filename: str, timeout: float):# Run this test in this process:full_plugin_filename = find_plugin_path(plugin_filename)try:cancel = threading.Event()+ with Watchdog():+ if timeout:+ threading.Thread(+ target=lambda: time.sleep(timeout) or cancel.set(),+ daemon=True,+ ).start()+ else:+ cancel.set()- if delay:- threading.Thread(target=lambda: time.sleep(delay) or cancel.set()).start()- else:- cancel.set()-- pedalboard.load_plugin(full_plugin_filename).show_editor(cancel)+ pedalboard.load_plugin(full_plugin_filename).show_editor(cancel)except Exception as e:if "no visual display devices available" in repr(e):pass@@ -918,7 +1030,7 @@ def test_show_editor_in_process(plugin_filename: str, delay: float):raise[email protected]("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", ONE_AVAILABLE_TEST_PLUGIN)@pytest.mark.parametrize("bad_input", [False, 1, {"foo": "bar"}, {"is_set": "False"}, threading.Event])@@ -937,13 +1049,13 @@ def test_show_editor_passed_something_else(plugin_filename: str, bad_input):not AVAILABLE_CONTAINER_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT,reason="No plugin containers installed in test environment!",)[email protected]("plugin_filename", AVAILABLE_CONTAINER_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT)-def test_plugin_container_handling(plugin_filename: str):+def test_plugin_container_handling():"""Some plugins can have multiple sub-plugins within them.As of v0.4.5, Pedalboard requires indicating the specific plugin to open within the container.These plugins will fail by default."""+ plugin_filename = AVAILABLE_CONTAINER_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT[0]with pytest.raises(ValueError) as e:load_test_plugin(plugin_filename, disable_caching=True)assert plugin_filename in str(e)@@ -960,7 +1072,7 @@ def test_plugin_container_handling(plugin_filename: str):assert plugin_name == plugin.name[email protected]("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", ONE_AVAILABLE_TEST_PLUGIN)def test_get_plugin_name_from_regular_plugin(plugin_filename: str):plugin_path = find_plugin_path(plugin_filename)if ".vst3" in plugin_filename:@@ -991,7 +1103,7 @@ def test_get_plugin_names_from_container(plugin_filename: str):assert len(names) > 1[email protected]("plugin_filename", AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT)[email protected]("plugin_filename", sample(AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT, 1))@pytest.mark.parametrize("num_plugins", [2, 4])def test_external_effect_plugin_concurrency(plugin_filename: str, num_plugins: int):plugins = [load_test_plugin(plugin_filename, disable_caching=True) for _ in range(num_plugins)]diff --git a/tests/test_filters.py b/tests/test_filters.pyindex 47c301d..3ba4f96 100644--- a/tests/test_filters.py+++ b/tests/test_filters.py@@ -15,10 +15,18 @@# limitations under the License.-import pytestimport numpy as np-from pedalboard import HighpassFilter, LowpassFilter, HighShelfFilter, LowShelfFilter, PeakFilter-from .utils import generate_sine_at, db_to_gain+import pytest++from pedalboard import (+ HighpassFilter,+ HighShelfFilter,+ LowpassFilter,+ LowShelfFilter,+ PeakFilter,+)++from .utils import db_to_gain, generate_sine_atdef rms(x: np.ndarray) -> float:@@ -69,7 +77,7 @@ def test_lowpass_slope(cutoff_frequency_hz, fundamental_hz, sample_rate, num_cha@pytest.mark.parametrize("fundamental_hz", [440, 880])@pytest.mark.parametrize("sample_rate", [22050, 44100, 48000])@pytest.mark.parametrize("num_channels", [1, 2])[email protected]("gain_db", [-12, -6, 0, 6, 12])[email protected]("gain_db", [-6, 0, 6])def test_shelf_filters(filter_type, fundamental_hz, sample_rate, num_channels, gain_db):sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_seconds=2, num_channels=num_channels@@ -85,9 +93,11 @@ def test_shelf_filters(filter_type, fundamental_hz, sample_rate, num_channels, g@pytest.mark.parametrize("fundamental_hz", [440, 880])@pytest.mark.parametrize("sample_rate", [22050, 44100, 48000])@pytest.mark.parametrize("num_channels", [1, 2])[email protected]("gain_db", [-12, -6, 0, 6, 12])[email protected]("gain_db", [-6, 0, 6])def test_peak_filter(fundamental_hz, sample_rate, num_channels, gain_db):- sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_seconds=2)+ sine_wave = generate_sine_at(+ sample_rate, fundamental_hz, num_channels=num_channels, num_seconds=2+ )filtered = PeakFilter(cutoff_frequency_hz=fundamental_hz, gain_db=gain_db)(sine_wave, sample_rate)@@ -100,7 +110,7 @@ def test_peak_filter(fundamental_hz, sample_rate, num_channels, gain_db):@pytest.mark.parametrize("fundamental_hz", [440, 880])@pytest.mark.parametrize("sample_rate", [22050, 44100, 48000])@pytest.mark.parametrize("num_channels", [1, 2])[email protected]("gain_db", [-12, -6, 0, 6, 12])[email protected]("gain_db", [-6, 0, 6])@pytest.mark.parametrize("q", [1 / np.sqrt(2), 1, 100])def test_q_factor(filter_type, fundamental_hz, sample_rate, num_channels, gain_db, q):sine_wave = generate_sine_at(diff --git a/tests/test_fixed_block_size.py b/tests/test_fixed_block_size.pyindex 9134dbd..9461280 100644--- a/tests/test_fixed_block_size.py+++ b/tests/test_fixed_block_size.py@@ -15,9 +15,11 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard_native._internal import FixedSizeBlockTestPlugin+from .utils import generate_sine_at@@ -26,7 +28,7 @@ from .utils import generate_sine_at@pytest.mark.parametrize("fixed_buffer_size", [1, 64, 65, 128, 8192, 8193])@pytest.mark.parametrize("num_channels", [1, 2])def test_fixed_size_blocks_plugin(sample_rate, buffer_size, fixed_buffer_size, num_channels):- signal = generate_sine_at(sample_rate, num_seconds=1.0, num_channels=num_channels)+ signal = generate_sine_at(sample_rate, num_seconds=0.10, num_channels=num_channels)plugin = FixedSizeBlockTestPlugin(fixed_buffer_size)output = plugin.process(signal, sample_rate, buffer_size=buffer_size)diff --git a/tests/test_gsm_compressor.py b/tests/test_gsm_compressor.pyindex b8cd4cc..9557fae 100644--- a/tests/test_gsm_compressor.py+++ b/tests/test_gsm_compressor.py@@ -15,9 +15,11 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard import GSMFullRateCompressor, Resample+from .utils import generate_sine_at# GSM is a _very_ lossy codec:@@ -28,8 +30,8 @@ SINE_WAVE_VOLUME = 0.9@pytest.mark.parametrize("fundamental_hz", [440.0])[email protected]("sample_rate", [8000, 11025, 32001.2345, 44100, 48000])[email protected]("buffer_size", [1, 32, 160, 1_000_000])[email protected]("sample_rate", [8000, 32001.2345, 44100, 48000])[email protected]("buffer_size", [32, 160, 1_000_000])@pytest.mark.parametrize("duration", [1.0])@pytest.mark.parametrize("quality",@@ -57,16 +59,10 @@ def test_gsm_compressor(np.testing.assert_allclose(signal, output, atol=GSM_ABSOLUTE_TOLERANCE)[email protected]("sample_rate", [8000, 44100])[email protected]("sample_rate", [44100])@pytest.mark.parametrize("quality",- [- Resample.Quality.ZeroOrderHold,- Resample.Quality.Linear,- Resample.Quality.Lagrange,- Resample.Quality.CatmullRom,- Resample.Quality.WindowedSinc,- ],+ [Resample.Quality.ZeroOrderHold, Resample.Quality.WindowedSinc],)@pytest.mark.parametrize("num_channels", [1, 2])def test_gsm_compressor_invariant_to_buffer_size(@@ -78,9 +74,9 @@ def test_gsm_compressor_invariant_to_buffer_size(duration = 3.0signal = generate_sine_at(sample_rate, fundamental_hz, duration, num_channels)+ compressor = GSMFullRateCompressor(quality=quality)compressed = [- GSMFullRateCompressor(quality=quality)(signal, sample_rate, buffer_size=buffer_size)- for buffer_size in (1, 32, 7000, 8192)+ compressor(signal, sample_rate, buffer_size=buffer_size) for buffer_size in (32, 7000, 8192)]for a, b in zip(compressed, compressed[1:]):np.testing.assert_allclose(a, b)diff --git a/tests/test_io.py b/tests/test_io.pyindex 0caf98c..b1df416 100644--- a/tests/test_io.py+++ b/tests/test_io.py@@ -24,6 +24,7 @@ import shutilimport timeimport wavefrom concurrent.futures import ThreadPoolExecutor+from functools import lru_cachefrom typing import Optionalimport mutagen@@ -62,6 +63,11 @@ UNSUPPORTED_FILENAMES = []+@lru_cache(maxsize=None)+def cached_rand(*args, **kwargs):+ return np.random.rand(*args, **kwargs)++def get_tolerance_for_format_and_bit_depth(extension: str, input_format, file_dtype: str) -> float:if not extension.startswith("."):extension = "." + extension@@ -347,7 +353,7 @@ def test_read_from_bytes_io_memoryview():stream = io.BytesIO()with pedalboard.io.AudioFile(stream, "w", 44100, 1, format="wav") as af:- af.write(np.random.rand(44100))+ af.write(cached_rand(44100))stream.seek(0)@@ -368,7 +374,7 @@ def test_read_from_bytes_io_with_offset():stream = io.BytesIO()with pedalboard.io.AudioFile(stream, "w", 44100, 1, format="wav") as af:- af.write(np.random.rand(44100))+ af.write(cached_rand(44100))# Prepend this buffer with random garbage:garbo = io.BytesIO(b"foobar" + stream.getvalue())@@ -389,7 +395,7 @@ def test_read_from_bytes_io_memoryview_without_gil():num_frames = 44100 * 1000with pedalboard.io.AudioFile(stream, "w", 44100, 1, format="wav") as af:- af.write(np.random.rand(num_frames))+ af.write(cached_rand(num_frames))num_cpus = os.cpu_count()@@ -433,7 +439,7 @@ def test_read_from_end_of_stream_produces_helpful_error_message(extension: str):buf = io.BytesIO()buf.name = f"something.{extension}"with pedalboard.io.AudioFile(buf, "w", 44100, 1) as af:- af.write(np.random.rand(44100))+ af.write(cached_rand(44100))buf.seek(len(buf.getvalue()))try:@@ -488,10 +494,10 @@ def test_file_like_exceptions_propagate_on_write():buf.write = eventually_throw_exceptionwith pedalboard.io.AudioFile(buf, "w", 44100, 1, format="wav") as af:- af.write(np.random.rand(44100))+ af.write(cached_rand(44100))should_throw[0] = Truewith pytest.raises(ValueError, match=r"Some kinda error!"):- af.write(np.random.rand(44100))+ af.write(cached_rand(44100))should_throw[0] = False@@ -601,13 +607,13 @@ def test_write_to_non_bytes_stream(extension: str):with pytest.raises(TypeError) as e:with pedalboard.io.AudioFile(stream, "w", 44100, 2, format=extension) as af:- af.write(np.random.rand(1, 2))+ af.write(cached_rand(1, 2))assert expected_message in str(e)with pytest.raises(TypeError) as e:with pedalboard.io.WriteableAudioFile(stream, 44100, 2, format=extension) as af:- af.write(np.random.rand(1, 2))+ af.write(cached_rand(1, 2))assert expected_message in str(e)@@ -858,12 +864,10 @@ def test_write_twice_overwrites(@pytest.mark.parametrize("extension", pedalboard.io.get_supported_write_formats())- "samplerate", [8000, 11025, 12000, 16000, 22050, 32000, 44100, 48000, 88200, 96000]-)[email protected]("samplerate", [8000, 96000])@pytest.mark.parametrize("num_channels", [1, 2, 3])@pytest.mark.parametrize("transposed", [False, True])[email protected]("input_format", [np.float32, np.float64, np.int8, np.int16, np.int32])[email protected]("input_format", [np.float32, np.int32])def test_write_matches_encode(extension: str, samplerate: float, num_channels: int, transposed: bool, input_format):@@ -968,7 +972,7 @@ def test_sample_rate_is_int_by_default(samplerate: int):buf = io.BytesIO()buf.name = "foo.wav"with pedalboard.io.AudioFile(buf, "w", samplerate=samplerate, num_channels=1) as f:- f.write(np.random.rand(100))+ f.write(cached_rand(100))buf.seek(0)with pedalboard.io.AudioFile(buf) as f:@@ -1276,10 +1280,10 @@ def test_mp3_duration_estimate(samplerate: float, target_samplerate: float, chunnum_frames = int(samplerate * 2)with pedalboard.io.AudioFile(buf, "w", samplerate, 2, quality=320) as f:- f.write(np.random.rand(2, num_frames))+ f.write(cached_rand(2, num_frames))# Write some random crap past the end of the file to break length estimation:- buf.write(np.random.rand(12345).tobytes())+ buf.write(cached_rand(12345).tobytes())# Skip the VBR header to force Pedalboard to estimate length:buf.seek(1044)@@ -1368,7 +1372,7 @@ def test_seek_accuracy(stream = io.BytesIO()stream.name = "foo" + extensionsr = 44100- input_audio = np.random.rand(sr).astype(np.float32)+ input_audio = cached_rand(sr).astype(np.float32)with pedalboard.io.AudioFile(stream, "w", sr, quality=quality) as f:f.write(input_audio)stream.seek(0)@@ -1415,7 +1419,7 @@ def test_flac_files_have_seektable():buf = io.BytesIO()buf.name = "test.flac"with pedalboard.io.AudioFile(buf, "w", 44100) as o:- o.write(np.random.rand(44100))+ o.write(cached_rand(44100))assert mutagen.File(buf).seektable, "Expected to write a FLAC seek table"@@ -1454,7 +1458,7 @@ def test_mp3_at_all_samplerates(quality: str, samplerate: float, num_channels: i# Make an audio signal that is equal parts noise and silence to make sure# we end up with a mixture of bitrates in the file:signal = np.concatenate(- [np.random.rand(samplerate * secs) - 0.5, np.zeros(samplerate * secs)]+ [cached_rand(samplerate * secs) - 0.5, np.zeros(samplerate * secs)]).astype(np.float32)if num_channels == 2:signal = np.stack([signal] * num_channels)@@ -1520,5 +1524,5 @@ def test_useful_exception_when_writing_to_unseekable_file_like():with pytest.raises(NotImplementedError) as e:with pedalboard.io.AudioFile(ILieAboutSeekability(), "w", 44100, 2) as f:- f.write(np.random.rand(2, 44100))+ f.write(cached_rand(2, 44100))assert "What's a seek?" in str(e)diff --git a/tests/test_latency_compensation.py b/tests/test_latency_compensation.pyindex d65d0fe..55b1860 100644--- a/tests/test_latency_compensation.py+++ b/tests/test_latency_compensation.py@@ -15,17 +15,21 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard_native._internal import AddLatency+MAX_SAMPLE_RATE = 96000+NUM_SECONDS = 3.0+NOISE = np.random.rand(int(NUM_SECONDS * MAX_SAMPLE_RATE)).astype(np.float32)+[email protected]("sample_rate", [22050, 44100, 48000])[email protected]("sample_rate", [22050, 44100, MAX_SAMPLE_RATE])@pytest.mark.parametrize("buffer_size", [128, 8192, 65536])[email protected]("latency_seconds", [0.25, 1, 2, 10])[email protected]("latency_seconds", [0.25, 1, 2])def test_latency_compensation(sample_rate, buffer_size, latency_seconds):- num_seconds = 10.0- noise = np.random.rand(int(num_seconds * sample_rate))+ noise = NOISE[: int(sample_rate * NUM_SECONDS)]plugin = AddLatency(int(latency_seconds * sample_rate))output = plugin.process(noise, sample_rate, buffer_size=buffer_size)np.testing.assert_allclose(output, noise)diff --git a/tests/test_mix_and_chain.py b/tests/test_mix_and_chain.pyindex fa4a370..959f18c 100644--- a/tests/test_mix_and_chain.py+++ b/tests/test_mix_and_chain.py@@ -15,23 +15,25 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard import (- Pedalboard,+ Chain,Compressor,Delay,Distortion,Gain,Mix,- Chain,+ Pedalboard,PitchShift,Reverb,)from pedalboard_native._internal import AddLatency--NUM_SECONDS = 4+NUM_SECONDS = 1+MAX_SAMPLE_RATE = 96000+NOISE = np.random.rand(int(NUM_SECONDS * MAX_SAMPLE_RATE)).astype(np.float32)def test_chain_access_like_list():@@ -63,7 +65,7 @@ def test_chain_access_like_list():def test_nested_chain():sr = 44100- _input = np.random.rand(int(NUM_SECONDS * sr), 2).astype(np.float32)+ _input = NOISE[: int(NUM_SECONDS * sr)]pb = Pedalboard([Gain(6), Chain([Gain(-6), Gain(1)]), Gain(-1)])output = pb(_input, sr)@@ -88,7 +90,7 @@ def test_nested_list_raises_error():def test_nested_mix():sr = 44100- _input = np.random.rand(int(NUM_SECONDS * sr), 2).astype(np.float32)+ _input = NOISE[: int(NUM_SECONDS * sr)]pb = Pedalboard([Gain(6), Mix([Gain(-6), Gain(-6)]), Gain(-6)])output = pb(_input, sr)@@ -107,7 +109,7 @@ def test_nested_mix():def test_deep_nesting():sr = 44100- _input = np.random.rand(int(NUM_SECONDS * sr), 2).astype(np.float32)+ _input = NOISE[: int(NUM_SECONDS * sr)]pb = Pedalboard([@@ -125,7 +127,7 @@ def test_deep_nesting():def test_nesting_pedalboards():sr = 44100- _input = np.random.rand(int(NUM_SECONDS * sr), 2).astype(np.float32)+ _input = NOISE[: int(NUM_SECONDS * sr)]pb = Pedalboard([@@ -151,7 +153,7 @@ def test_nesting_pedalboards():@pytest.mark.parametrize("latency_a_seconds", [0.25, 1, NUM_SECONDS / 2])@pytest.mark.parametrize("latency_b_seconds", [0.25, 1, NUM_SECONDS / 2])def test_mix_latency_compensation(sample_rate, buffer_size, latency_a_seconds, latency_b_seconds):- noise = np.random.rand(int(NUM_SECONDS * sample_rate))+ noise = NOISE[: int(NUM_SECONDS * sample_rate)]pb = Pedalboard([Mix(@@ -173,7 +175,7 @@ def test_mix_latency_compensation(sample_rate, buffer_size, latency_a_seconds, l@pytest.mark.parametrize("latency_a_seconds", [0.25, 1, 2, 10])@pytest.mark.parametrize("latency_b_seconds", [0.25, 1, 2, 10])def test_chain_latency_compensation(sample_rate, buffer_size, latency_a_seconds, latency_b_seconds):- noise = np.random.rand(int(NUM_SECONDS * sample_rate))+ noise = NOISE[: int(NUM_SECONDS * sample_rate)]pb = Pedalboard([Chain(@@ -197,7 +199,7 @@ def test_chain_latency_compensation(sample_rate, buffer_size, latency_a_seconds,@pytest.mark.parametrize("sample_rate", [22050, 44100, 48000])@pytest.mark.parametrize("buffer_size", [128, 8192, 65536])def test_readme_example_does_not_crash(sample_rate, buffer_size):- noise = np.random.rand(int(NUM_SECONDS * sample_rate))+ noise = NOISE[: int(NUM_SECONDS * sample_rate)]passthrough = Gain(gain_db=0)@@ -242,10 +244,10 @@ def test_readme_example_does_not_crash(sample_rate, buffer_size):original_plus_delayed_harmonies(noise, sample_rate=sample_rate, buffer_size=buffer_size)[email protected]("sample_rate", [22050, 44100, 48000])[email protected]("buffer_size", [128, 8192, 65536])[email protected]("sample_rate", [22050])[email protected]("buffer_size", [65536])def test_pedalboard_is_a_plugin(sample_rate, buffer_size):- noise = np.random.rand(int(NUM_SECONDS * sample_rate))+ noise = NOISE[: int(NUM_SECONDS * sample_rate)]passthrough = Gain(gain_db=0)@@ -306,6 +308,6 @@ def test_none_as_argument(cls):assert len(container) == 1assert container[0] is Nonesample_rate = 44100- noise = np.random.rand(int(NUM_SECONDS * sample_rate))+ noise = NOISE[: int(NUM_SECONDS * sample_rate)]output = container(noise, sample_rate)np.testing.assert_allclose(noise, output)diff --git a/tests/test_mp3_compressor.py b/tests/test_mp3_compressor.pyindex 6354c03..f48ddb9 100644--- a/tests/test_mp3_compressor.py+++ b/tests/test_mp3_compressor.py@@ -15,9 +15,11 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard import MP3Compressor+from tests.utils import generate_sine_at# For the range of VBR quality levels supported by LAME,# all output samples will match all input samples within@@ -25,20 +27,7 @@ from pedalboard import MP3CompressorMP3_ABSOLUTE_TOLERANCE = 0.25-def generate_sine_at(- sample_rate: float,- fundamental_hz: float = 440.0,- num_seconds: float = 3.0,- num_channels: int = 1,-) -> np.ndarray:- samples = np.arange(num_seconds * sample_rate)- sine_wave = np.sin(2 * np.pi * fundamental_hz * samples / sample_rate)- if num_channels == 2:- sine_wave = np.stack([sine_wave, sine_wave])- return sine_wave--[email protected]("vbr_quality", [0.0, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9.5])[email protected]("vbr_quality", [0.0, 0.5, 1, 9, 9.5])@pytest.mark.parametrize("sample_rate", [44100, 48000])@pytest.mark.parametrize("num_channels", [1, 2])def test_mp3_compressor(vbr_quality: float, sample_rate: int, num_channels: int):@@ -47,7 +36,7 @@ def test_mp3_compressor(vbr_quality: float, sample_rate: int, num_channels: int)np.testing.assert_allclose(sine_wave, compressed, atol=MP3_ABSOLUTE_TOLERANCE)[email protected]("vbr_quality", [0.0, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9.5])[email protected]("vbr_quality", [0.0, 0.5, 1, 9, 9.5])@pytest.mark.parametrize("sample_rate", [44100, 48000])@pytest.mark.parametrize("num_channels", [1, 2])def test_mp3_compressor_invariant_to_buffer_size(@@ -55,9 +44,10 @@ def test_mp3_compressor_invariant_to_buffer_size():sine_wave = generate_sine_at(sample_rate, num_channels=num_channels)+ compressor = MP3Compressor(vbr_quality)compressed_different_buffer_sizes = [- MP3Compressor(vbr_quality)(sine_wave, sample_rate, buffer_size=buffer_size)- for buffer_size in (1, 32, 128, 1024, 1152, 8192, 65536)+ compressor(sine_wave, sample_rate, buffer_size=buffer_size)+ for buffer_size in (1, 128, 1152, 65536)]# These should all be the same, so any two should be the same:@@ -70,15 +60,10 @@ def test_mp3_compressor_invariant_to_buffer_size("sample_rate", [48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000])@pytest.mark.parametrize("num_channels", [1, 2])[email protected]("buffer_size", [32, 8192])def test_mp3_compressor_arbitrary_sample_rate(- vbr_quality: float,- sample_rate: int,- num_channels: int,- buffer_size: int,+ vbr_quality: float, sample_rate: int, num_channels: int):sine_wave = generate_sine_at(sample_rate, num_channels=num_channels)-compressed = MP3Compressor(vbr_quality)(sine_wave, sample_rate)np.testing.assert_allclose(sine_wave, compressed, atol=MP3_ABSOLUTE_TOLERANCE)diff --git a/tests/test_priming.py b/tests/test_priming.pyindex 03f29c0..cda6011 100644--- a/tests/test_priming.py+++ b/tests/test_priming.py@@ -15,20 +15,21 @@# limitations under the License.-import pytestimport numpy as np+import pytest+from pedalboard_native._internal import PrimeWithSilenceTestPlugin+NUM_SECONDS = 1+MAX_SAMPLE_RATE = 48000+NOISE = np.random.rand(int(NUM_SECONDS * MAX_SAMPLE_RATE)).astype(np.float32)+@pytest.mark.parametrize("sample_rate", [22050, 44100, 48000])@pytest.mark.parametrize("buffer_size", [16, 40, 128, 160, 8192, 8193])@pytest.mark.parametrize("silent_samples_to_add", [1, 16, 40, 128, 160, 8192, 8193])[email protected]("num_channels", [1, 2])-def test_prime_with_silence(sample_rate, buffer_size, silent_samples_to_add, num_channels):- num_seconds = 5.0- noise = np.random.rand(int(num_seconds * sample_rate))- if num_channels == 2:- noise = np.stack([noise, noise])+def test_prime_with_silence(sample_rate, buffer_size, silent_samples_to_add):+ noise = NOISE[: int(sample_rate * NUM_SECONDS)]plugin = PrimeWithSilenceTestPlugin(silent_samples_to_add)output = plugin.process(noise, sample_rate, buffer_size=buffer_size)np.testing.assert_allclose(output, noise)diff --git a/tests/utils.py b/tests/utils.pyindex acedb4b..f8892f6 100644--- a/tests/utils.py+++ b/tests/utils.py@@ -1,28 +1,27 @@-import numpy as np+from functools import lru_cache+import numpy as npTEST_SINE_WAVE_CACHE = {}+@lru_cache(maxsize=None)def generate_sine_at(sample_rate: float,fundamental_hz: float = 440.0,- num_seconds: float = 3.0,+ num_seconds: float = 1.0,num_channels: int = 1,) -> np.ndarray:- cache_key = "-".join([str(x) for x in [sample_rate, fundamental_hz, num_seconds, num_channels]])- if cache_key not in TEST_SINE_WAVE_CACHE:- samples = np.arange(num_seconds * sample_rate)- sine_wave = np.sin(2 * np.pi * fundamental_hz * samples / sample_rate)- # Fade the sine wave in at the start and out at the end to remove any transients:- fade_duration = int(sample_rate * 0.1)- sine_wave[:fade_duration] *= np.linspace(0, 1, fade_duration)- sine_wave[-fade_duration:] *= np.linspace(1, 0, fade_duration)- if num_channels != 1:- TEST_SINE_WAVE_CACHE[cache_key] = np.stack([sine_wave] * num_channels)- else:- TEST_SINE_WAVE_CACHE[cache_key] = sine_wave- return TEST_SINE_WAVE_CACHE[cache_key]+ samples = np.arange(num_seconds * sample_rate)+ sine_wave = np.sin(2 * np.pi * fundamental_hz * samples / sample_rate)+ # Fade the sine wave in at the start and out at the end to remove any transients:+ fade_duration = int(sample_rate * 0.1)+ sine_wave[:fade_duration] *= np.linspace(0, 1, fade_duration)+ sine_wave[-fade_duration:] *= np.linspace(1, 0, fade_duration)+ if num_channels != 1:+ return np.stack([sine_wave] * num_channels)+ else:+ return sine_wavedef db_to_gain(db: float) -> float:diff --git a/tox.ini b/tox.iniindex 8125f6c..775aa41 100644--- a/tox.ini+++ b/tox.ini@@ -54,5 +54,5 @@ ignore = W503,E203exclude = .venv,.tox,.git,dist,doc,*.egg,build,vendors[pytest]-addopts = -v+addopts =testpaths = testsdiff --git a/vendors/pybind11 b/vendors/pybind11new file mode 160000index 0000000..19a6b9f--- /dev/null+++ b/vendors/pybind11@@ -0,0 +1 @@+Subproject commit 19a6b9f4efb569129c878b7f8db09132248fbaa1