From 95778d77d52ac3e5df83ce3c15592ef673e83951 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Tue, 10 Jan 2023 21:18:50 +0100 Subject: [PATCH 01/17] Added .drone requires image archlinux_build --- .drone.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..1bfd77e --- /dev/null +++ b/.drone.yml @@ -0,0 +1,13 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: build + image: archlinux_build + pull: if-not-exists + commands: + - cmake . + - make -j + + From e128cc69ec7ee1d95aa21618984a9d7e67d0c67c Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Tue, 10 Jan 2023 21:50:48 +0100 Subject: [PATCH 02/17] Updated drone config. Cached compilation --- .drone.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++-- README.md | 2 ++ requirements.txt | 3 +++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/.drone.yml b/.drone.yml index 1bfd77e..7f76c42 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,12 +2,54 @@ kind: pipeline type: docker name: default +clone: + depth: 3 + steps: - - name: build + - name: restore-cache-with-filesystem + image: meltwater/drone-cache + pull: true + settings: + backend: "filesystem" + restore: true + cache_key: "volume" + archive_format: "gzip" + # filesystem_cache_root: "/tmp/cache" + mount: + - 'vendor' + volumes: + - name: cache + path: /tmp/cache + + - name: build-release-arch image: archlinux_build pull: if-not-exists commands: + - pacman -S pybind11 openblas fftw pulseaudio + - git submodule update --init --recursive - cmake . - - make -j + # More than two makes ascee2 irresponsive for now + - make -j2 + + - name: rebuild-cache-with-filesystem + image: meltwater/drone-cache + pull: true + settings: + backend: "filesystem" + rebuild: true + cache_key: "volume" + archive_format: "gzip" + # filesystem_cache_root: "/tmp/cache" + mount: + - 'vendor' + volumes: + - name: cache + path: /tmp/cache + +volumes: + - name: cache + host: + path: /var/lib/cache +--- diff --git a/README.md b/README.md index 98bfcc0..6125789 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Library for Acoustic Signal Processing +[![Build Status](https://drone.ascee.nl/api/badges/ASCEE/lasp/status.svg)](https://drone.ascee.nl/ASCEE/lasp) + Welcome to LASP: Library for Acoustic Signal Processing. LASP is a C++ library with a Python interface which is supposed to process (multi-) microphone acoustic data in real time on a PC and output results. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e985c14 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +dataclasses_json +h5py + From 6872988e49a10310de7644eaef3d8926e7ca24d8 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Tue, 10 Jan 2023 21:52:08 +0100 Subject: [PATCH 03/17] Bugfix yaml drone --- .drone.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 7f76c42..17969e0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -50,6 +50,5 @@ volumes: - name: cache host: path: /var/lib/cache ---- From d50e419ba8e39caf586978e524594a824bee179f Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 12:02:05 +0100 Subject: [PATCH 04/17] Now testing without cache --- .drone.yml | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/.drone.yml b/.drone.yml index 17969e0..7a3959f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,26 +1,11 @@ kind: pipeline type: docker -name: default +name: archlinux_build clone: depth: 3 steps: - - name: restore-cache-with-filesystem - image: meltwater/drone-cache - pull: true - settings: - backend: "filesystem" - restore: true - cache_key: "volume" - archive_format: "gzip" - # filesystem_cache_root: "/tmp/cache" - mount: - - 'vendor' - volumes: - - name: cache - path: /tmp/cache - - name: build-release-arch image: archlinux_build pull: if-not-exists @@ -31,24 +16,3 @@ steps: # More than two makes ascee2 irresponsive for now - make -j2 - - name: rebuild-cache-with-filesystem - image: meltwater/drone-cache - pull: true - settings: - backend: "filesystem" - rebuild: true - cache_key: "volume" - archive_format: "gzip" - # filesystem_cache_root: "/tmp/cache" - mount: - - 'vendor' - volumes: - - name: cache - path: /tmp/cache - -volumes: - - name: cache - host: - path: /var/lib/cache - - From 126e873d22c54cd3aa61f3f05969b253568170e1 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 12:05:04 +0100 Subject: [PATCH 05/17] Removed comand of submodule update --- .drone.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 7a3959f..3a9c051 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,7 +11,6 @@ steps: pull: if-not-exists commands: - pacman -S pybind11 openblas fftw pulseaudio - - git submodule update --init --recursive - cmake . # More than two makes ascee2 irresponsive for now - make -j2 From 2f1ddb5bfa5b114f02d47b0636d41678e3a4ec78 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 12:09:25 +0100 Subject: [PATCH 06/17] Forgot noconfirm in pacman --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 3a9c051..28f9891 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,7 @@ steps: image: archlinux_build pull: if-not-exists commands: - - pacman -S pybind11 openblas fftw pulseaudio + - pacman -S --noconfirm pybind11 openblas fftw pulseaudio - cmake . # More than two makes ascee2 irresponsive for now - make -j2 From 38ad65291da975234fa7d08d61ce0cbbc755334c Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 12:31:12 +0100 Subject: [PATCH 07/17] Further on... --- .drone.yml | 35 +++++++++++++++++++++++++++++++++-- README.md | 2 +- requirements.txt | 1 + 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 28f9891..b19a2e2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,12 +6,43 @@ clone: depth: 3 steps: - - name: build-release-arch + - name: build-arch image: archlinux_build pull: if-not-exists + volumes: + - name: archlinux_ccache + path: /root/.ccache commands: - - pacman -S --noconfirm pybind11 openblas fftw pulseaudio + - pacman -S --noconfirm ccache openblas fftw pulseaudio + - pip install -r requirements.txt - cmake . # More than two makes ascee2 irresponsive for now - make -j2 + - name: test-arch + image: archlinux_build + pull: if-not-exists + commands: + - pacman -S --noconfirm openblas fftw pulseaudio python-pip python-scipy + - pip install -r requirements.txt + - pip install . + - pytest +volumes: + - name: archlinux_ccache + host: + path: /tmp/archlinux_ccache + +--- +kind: pipeline +type: docker +name: ubuntu_build + +clone: + depth: 3 + +steps: + - name: build-ubuntu + image: ubuntu + pull: if-not-exists + commands: + - echo "Hello world" diff --git a/README.md b/README.md index 39e3a07..7c0fc19 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ If you have any question(s), please feel free to contact us: info@ascee.nl. ## Dependencies -- `$ sudo apt install libopenblas-dev python3-pip python3-scipy libusb-dev libpulse-dev cmake-curses-gui python3-h5py` +- `$ sudo apt install python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-dev libpulse-dev cmake-curses-gui python3-h5py` - `$ pip3 install --user -r requirements.txt` diff --git a/requirements.txt b/requirements.txt index c46d0e7..c7a9274 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ appdirs dataclasses_json +matplotlib From 22f41b1583d6fc1e20c1341f3f5021808139c8ad Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 14:11:12 +0100 Subject: [PATCH 08/17] Build test split arch --- .drone.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index b19a2e2..43732d5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,7 +3,7 @@ type: docker name: archlinux_build clone: - depth: 3 + depth: 50 steps: - name: build-arch @@ -14,7 +14,6 @@ steps: path: /root/.ccache commands: - pacman -S --noconfirm ccache openblas fftw pulseaudio - - pip install -r requirements.txt - cmake . # More than two makes ascee2 irresponsive for now - make -j2 From 80c334d87154972e98e25c946ac5238a14074938 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 14:13:20 +0100 Subject: [PATCH 09/17] Added pybind11 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 43732d5..5f5f5cc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ steps: - name: archlinux_ccache path: /root/.ccache commands: - - pacman -S --noconfirm ccache openblas fftw pulseaudio + - pacman -S --noconfirm ccache openblas fftw pulseaudio pybind11 - cmake . # More than two makes ascee2 irresponsive for now - make -j2 From b2a61336252659052152430f8f93630e37370663 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 14:16:40 +0100 Subject: [PATCH 10/17] Submodule initialization should be done manually --- .drone.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 5f5f5cc..b34fd08 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,6 +13,7 @@ steps: - name: archlinux_ccache path: /root/.ccache commands: + - git submodule update --init --recursive - pacman -S --noconfirm ccache openblas fftw pulseaudio pybind11 - cmake . # More than two makes ascee2 irresponsive for now @@ -44,4 +45,4 @@ steps: image: ubuntu pull: if-not-exists commands: - - echo "Hello world" + - git submodule update --init --recursive From 0d65b1316bb54fc6f11210b7f89f977bdd54ddf0 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 14:23:16 +0100 Subject: [PATCH 11/17] Added pytest as pacman dep --- .drone.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index b34fd08..524e282 100644 --- a/.drone.yml +++ b/.drone.yml @@ -18,15 +18,20 @@ steps: - cmake . # More than two makes ascee2 irresponsive for now - make -j2 + - name: test-arch image: archlinux_build pull: if-not-exists commands: - - pacman -S --noconfirm openblas fftw pulseaudio python-pip python-scipy + - pacman -S --noconfirm openblas python-pytest fftw pulseaudio python-pip python-scipy - pip install -r requirements.txt - pip install . - pytest + # - name: release-arch + # commands: + # - + volumes: - name: archlinux_ccache host: From 54b2fcc5e9f585104d3ab7ba6eec3da77cb91075 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 14:39:17 +0100 Subject: [PATCH 12/17] Possible candidate for ubuntu build and arch build --- .drone.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.drone.yml b/.drone.yml index 524e282..5540b61 100644 --- a/.drone.yml +++ b/.drone.yml @@ -45,9 +45,36 @@ name: ubuntu_build clone: depth: 3 +volumes: +- name: archlinux_ccache + path: /root/.ccache + steps: - name: build-ubuntu image: ubuntu pull: if-not-exists + volumes: + - name: ubuntu_ccache + path: /root/.ccache commands: + - apt update + - apt install -y git python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-1.0-0-dev libpulse-dev python3-h5py fftw-dev - git submodule update --init --recursive + - cmake . + # More than two makes ascee2 irresponsive for now + - make -j2 + + - name: test-ubuntu + image: ubuntu_build + pull: if-not-exists + commands: + - apt update + - apt install -y python3-pytest fftw pulseaudio python3-pip python3-scipy + - pip install -r requirements.txt + - pip install . + - pytest-3 + +volumes: + - name: ubuntu_ccache + host: + path: /tmp/ubuntu_ccache From f012244091a6c7623809158dacee2b120f484df5 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 17:03:40 +0100 Subject: [PATCH 13/17] Pyproject and setup do not cooperate. Removed pyproject.toml --- README.md | 2 +- pyproject.toml | 17 ----------------- setup.py | 24 ++++++++++++------------ 3 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 pyproject.toml diff --git a/README.md b/README.md index 7c0fc19..0813ac8 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ If you have any question(s), please feel free to contact us: info@ascee.nl. ## Dependencies -- `$ sudo apt install python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-dev libpulse-dev cmake-curses-gui python3-h5py` +- `$ sudo apt install python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-1.0-0-dev libpulse-dev cmake-curses-gui python3-h5py` - `$ pip3 install --user -r requirements.txt` diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 6ac7893..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,17 +0,0 @@ -[project] # Project metadata -name = "lasp" -readme = "README.md" -requires-python = ">=3.8" -license = { "file" = "LICENSE" } -authors = [{ "name" = "J.A. de Jong et al.", "email" = "info@ascee.nl" }] - -classifiers = [ - "Topic :: Scientific/Engineering", - "Programming Language :: Python :: 3.8", - "Operating System :: POSIX :: Linux", - "Operating System :: Microsoft :: Windows", -] - -# urls = { "Documentation" = "https://" } -dynamic = ["version", "description"] - diff --git a/setup.py b/setup.py index b46819d..ca521c8 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,20 @@ -import glob +import glob, os import platform from setuptools import setup if 'Linux' in platform.platform(): - extension = list(glob.glob('src/lasp/lasp_cpp.cpython*')) - if len(extension) == 0: + ext_name_glob = 'lasp_cpp.cpython*' + extensions = list(glob.glob('src/lasp/' + ext_name_glob)) + ext_names = [os.path.split(a)[1] for a in extensions] + + print(extensions) + if len(extensions) == 0: raise RuntimeError('Please first run CMake to build extension') - elif len(extension) > 1: + elif len(extensions) > 1: raise RuntimeError('Too many extension files found') - pkgdata = extension + pkgdata = ext_names else: raise RuntimeError('Not yet Windows-proof') @@ -24,9 +28,6 @@ classifiers = [ keywords = ["DSP", "DAQ", "Signal processing"] -with open('README.md', 'r') as f: - readme = f.read() - setup( name="lasp", @@ -40,12 +41,11 @@ setup( classifiers=classifiers, keywords=keywords, license="MIT", - readme=readme, dependencies=["numpy", "scipy", "appdirs", "h5py", "appdirs", - "dataclasses_json"], + "dataclasses_json"], + package_dir={"": "src"}, packages=['lasp', 'lasp.filter', 'lasp.tools'], - data_files = pkgdata, include_package_data=True, - package_dir={'': 'src'}, + package_data={'lasp': pkgdata}, python_requires='>=3.8', ) From e86913a2080f6b128fafaec85c59f4a110a9fcc5 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 19:49:32 +0100 Subject: [PATCH 14/17] Take 2 on Ubuntu, better handling of extension code --- .drone.yml | 18 +++++++++--------- setup.py | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5540b61..7fb8b26 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,12 +1,12 @@ kind: pipeline type: docker -name: archlinux_build +name: archlinux clone: depth: 50 steps: - - name: build-arch + - name: archlinux_build image: archlinux_build pull: if-not-exists volumes: @@ -19,7 +19,7 @@ steps: # More than two makes ascee2 irresponsive for now - make -j2 - - name: test-arch + - name: archlinux_test image: archlinux_build pull: if-not-exists commands: @@ -40,7 +40,7 @@ volumes: --- kind: pipeline type: docker -name: ubuntu_build +name: ubuntu clone: depth: 3 @@ -50,7 +50,7 @@ volumes: path: /root/.ccache steps: - - name: build-ubuntu + - name: ubuntu_build image: ubuntu pull: if-not-exists volumes: @@ -58,18 +58,18 @@ steps: path: /root/.ccache commands: - apt update - - apt install -y git python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-1.0-0-dev libpulse-dev python3-h5py fftw-dev + - apt install -y git cmake python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-1.0-0-dev libpulse-dev python3-h5py fftw-dev - git submodule update --init --recursive - cmake . # More than two makes ascee2 irresponsive for now - make -j2 - - name: test-ubuntu - image: ubuntu_build + - name: ubuntu_test + image: ubuntu pull: if-not-exists commands: - apt update - - apt install -y python3-pytest fftw pulseaudio python3-pip python3-scipy + - apt install -y python3-pytest fftw pulseaudio python3-pip python3-scipy python3-h5py - pip install -r requirements.txt - pip install . - pytest-3 diff --git a/setup.py b/setup.py index ca521c8..66ceecd 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,8 @@ from setuptools import setup if 'Linux' in platform.platform(): ext_name_glob = 'lasp_cpp.cpython*' extensions = list(glob.glob('src/lasp/' + ext_name_glob)) + + # Split of path from file. ext_names = [os.path.split(a)[1] for a in extensions] print(extensions) From 3da6595b0c768d476bf3dea4abcd60764ca67b87 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 20:13:42 +0100 Subject: [PATCH 15/17] No downloading of requirements anymore --- .drone.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index 7fb8b26..be7f37f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,8 +13,10 @@ steps: - name: archlinux_ccache path: /root/.ccache commands: + # The following command is not required, we included this in the docker + # image of archlinux_build + # - pacman -S --noconfirm ccache openblas fftw pulseaudio pybind11 - git submodule update --init --recursive - - pacman -S --noconfirm ccache openblas fftw pulseaudio pybind11 - cmake . # More than two makes ascee2 irresponsive for now - make -j2 @@ -23,7 +25,9 @@ steps: image: archlinux_build pull: if-not-exists commands: - - pacman -S --noconfirm openblas python-pytest fftw pulseaudio python-pip python-scipy + # The following command is not required, we included this in the docker + # image of archlinux_build + # - pacman -S --noconfirm openblas python-pytest fftw pulseaudio python-pip python-scipy python-h5py - pip install -r requirements.txt - pip install . - pytest @@ -57,8 +61,10 @@ steps: - name: ubuntu_ccache path: /root/.ccache commands: - - apt update - - apt install -y git cmake python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-1.0-0-dev libpulse-dev python3-h5py fftw-dev + # The following commands are not required, we included this in the docker + # image of ubuntu_build + #- apt update + #- apt install -y git cmake python3-pybind11 libopenblas-dev python3-pip python3-scipy libusb-1.0-0-dev libpulse-dev python3-h5py fftw-dev - git submodule update --init --recursive - cmake . # More than two makes ascee2 irresponsive for now @@ -68,8 +74,10 @@ steps: image: ubuntu pull: if-not-exists commands: - - apt update - - apt install -y python3-pytest fftw pulseaudio python3-pip python3-scipy python3-h5py + # The following commands are not required, we included this in the docker + # image of ubuntu_build + #- apt update + #- apt install -y python3-pytest fftw pulseaudio python3-pip python3-scipy python3-h5py - pip install -r requirements.txt - pip install . - pytest-3 From d1dea1483f53b69e7813518f7e8185e59ce6fbf5 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 20:31:55 +0100 Subject: [PATCH 16/17] Updated tests --- .../example_biquadbank.py | 7 +- test/test_aps.py | 2 - test/test_cppslm.py | 89 ++++++++++--------- 3 files changed, 48 insertions(+), 50 deletions(-) rename test/test_biquadbank.py => examples/example_biquadbank.py (88%) diff --git a/test/test_biquadbank.py b/examples/example_biquadbank.py similarity index 88% rename from test/test_biquadbank.py rename to examples/example_biquadbank.py index be0a1da..1f5315a 100644 --- a/test/test_biquadbank.py +++ b/examples/example_biquadbank.py @@ -2,15 +2,10 @@ import numpy as np from lasp import SeriesBiquad, AvPowerSpectra from lasp.filter import SPLFilterDesigner - import matplotlib.pyplot as plt from scipy.signal import sosfreqz -# plt.close('all') +plt.close('all') -# def test_cppslm2(): -# """ -# Generate a sine wave, now A-weighted -# """ fs = 48000 omg = 2*np.pi*1000 diff --git a/test/test_aps.py b/test/test_aps.py index 4ec248f..1e78498 100644 --- a/test/test_aps.py +++ b/test/test_aps.py @@ -8,8 +8,6 @@ Created on Mon Jan 15 19:45:33 2018 import numpy as np from lasp import AvPowerSpectra, Window -import matplotlib.pyplot as plt -# plt.close('all') def test_aps1(): nfft = 16384 diff --git a/test/test_cppslm.py b/test/test_cppslm.py index 5890b8d..ab3dbb8 100644 --- a/test/test_cppslm.py +++ b/test/test_cppslm.py @@ -2,34 +2,35 @@ import numpy as np from lasp import cppSLM from lasp.filter import SPLFilterDesigner -import matplotlib.pyplot as plt + def test_cppslm1(): """ Generate a sine wave """ fs = 48000 - omg = 2*np.pi*1000 - - slm = cppSLM.fromBiquads(fs, 2e-5, 1, 0.125, [1.,0,0,1,0,0]) - - t = np.linspace(0, 10, 10*fs, endpoint=False) + omg = 2 * np.pi * 1000 + + slm = cppSLM.fromBiquads(fs, 2e-5, 1, 0.125, + np.array([[1., 0, 0, 1, 0, 0]]).T) + + t = np.linspace(0, 10, 10 * fs, endpoint=False) + + # Input signal with an rms of 1 Pa + in_ = np.sin(omg * t) * np.sqrt(2) - # Input signal with an rms of 1 Pa - in_ = np.sin(omg*t)*np.sqrt(2) - # Compute overall RMS - rms = np.sqrt(np.sum(in_**2)/in_.size) + rms = np.sqrt(np.sum(in_**2) / in_.size) # Compute overall level - level = 20*np.log10(rms/2e-5) - + level = 20 * np.log10(rms / 2e-5) + # Output of SLM out = slm.run(in_) - + # Output of SLM should be close to theoretical # level, at least for reasonable time constants # (Fast, Slow etc) - assert(np.isclose(out[-1,0], level)) + assert (np.isclose(out[-1, 0], level)) def test_cppslm2(): @@ -37,53 +38,57 @@ def test_cppslm2(): Generate a sine wave, now A-weighted """ fs = 48000 - omg = 2*np.pi*1000 - + omg = 2 * np.pi * 1000 + filt = SPLFilterDesigner(fs).A_Sos_design() - slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125, filt.flatten(), [1.,0,0,1,0,0]) - - t = np.linspace(0, 10, 10*fs, endpoint=False) - - # Input signal with an rms of 1 Pa - in_ = np.sin(omg*t) *np.sqrt(2) - + slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125, + filt.flatten(), # Pre-filter coefs + np.array([[1., 0, 0, 1, 0, 0]]).T # Bandpass coefs + ) + + t = np.linspace(0, 10, 10 * fs, endpoint=False) + + # Input signal with an rms of 1 Pa + in_ = np.sin(omg * t) * np.sqrt(2) + # Compute overall RMS - rms = np.sqrt(np.sum(in_**2)/in_.size) + rms = np.sqrt(np.sum(in_**2) / in_.size) # Compute overall level - level = 20*np.log10(rms/2e-5) - + level = 20 * np.log10(rms / 2e-5) + # Output of SLM out = slm.run(in_) # Output of SLM should be close to theoretical # level, at least for reasonable time constants # (Fast, Slow etc) - assert np.isclose(out[-1,0], level, atol=1e-2) + assert np.isclose(out[-1, 0], level, atol=1e-2) + def test_cppslm3(): fs = 48000 - omg = 2*np.pi*1000 - + omg = 2 * np.pi * 1000 + filt = SPLFilterDesigner(fs).A_Sos_design() - slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125, filt.flatten(), [1.,0,0,1,0,0]) - t = np.linspace(0, 10, 10*fs, endpoint=False) - - in_ = 10*np.sin(omg*t) * np.sqrt(2)+np.random.randn() + slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125, + filt.flatten(), + np.array([[1., 0, 0, 1, 0, 0]]).T) + t = np.linspace(0, 10, 10 * fs, endpoint=False) + + in_ = 10 * np.sin(omg * t) * np.sqrt(2) + np.random.randn() # Compute overall RMS - rms = np.sqrt(np.sum(in_**2)/in_.size) + rms = np.sqrt(np.sum(in_**2) / in_.size) # Compute overall level - level = 20*np.log10(rms/2e-5) - - + level = 20 * np.log10(rms / 2e-5) + # Output of SLM out = slm.run(in_) - - Lpeak = 20*np.log10(np.max(np.abs(in_)/2e-5)) + + Lpeak = 20 * np.log10(np.max(np.abs(in_) / 2e-5)) Lpeak slm.Lpeak() - assert np.isclose(out[-1,0], slm.Leq()[0][0], atol=1e-2) - assert np.isclose(Lpeak, slm.Lpeak()[0][0], atol=2e0) - + assert np.isclose(out[-1, 0], slm.Leq()[0], atol=1e-2) + assert np.isclose(Lpeak, slm.Lpeak()[0], atol=2e0) if __name__ == '__main__': From 0ed005e35f7d6e421f76948b0cfe72b0643adf4b Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 12 Jan 2023 20:35:00 +0100 Subject: [PATCH 17/17] Cleanup of tests --- test/test_ps.py | 2 -- test/test_slm.py | 37 ------------------------------------- 2 files changed, 39 deletions(-) delete mode 100644 test/test_slm.py diff --git a/test/test_ps.py b/test/test_ps.py index b320da9..cb238a5 100644 --- a/test/test_ps.py +++ b/test/test_ps.py @@ -5,8 +5,6 @@ Testing code for power spectra """ import numpy as np from lasp import PowerSpectra, Window -# import matplotlib.pyplot as plt -# plt.close('all') def test_ps(): """ diff --git a/test/test_slm.py b/test/test_slm.py deleted file mode 100644 index 1596262..0000000 --- a/test/test_slm.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python3 -import numpy as np -from lasp import SLM - - - -nframes = 0 -samplerate = 48000 -omg = 2*np.pi*1000 - - - -# def mycallback(input_, nframes, streamtime): -# t = np.linspace(streamtime, streamtime + nframes/samplerate, -# nframes)[np.newaxis,:] -# outp = 0.1*np.sin(omg*t) -# return outp, 0 - -# if __name__ == '__main__': -# pa = RtAudio() -# count = pa.getDeviceCount() -# # dev = pa.getDeviceInfo(0) -# for i in range(count): -# dev = pa.getDeviceInfo(i) -# print(dev) - -# outputparams = {'deviceid': 0, 'nchannels': 1, 'firstchannel': 0} -# pa.openStream(outputparams, None , Format_FLOAT64,samplerate, 512, mycallback) -# pa.startStream() - -# input() - -# pa.stopStream() -# pa.closeStream() - - -