From 0d79bbd2af12aafe7493211e3b784c5d2a918f21 Mon Sep 17 00:00:00 2001 From: HEnquist Date: Thu, 29 Oct 2020 22:49:35 +0100 Subject: [PATCH] Update readme, bump version 0.4.0 --- README.md | 28 ++++++++++++++++++++++------ camilladsp_plot/eval_filterconfig.py | 2 +- setup.py | 2 +- tests/test_filtereval.py | 11 ++++------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 17ef4da..41d68fe 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ pip install . Note that on some systems the command is `pip3` instead of `pip`. ## Requirements -This library requires Python 3.6 or newer, and both `numpy` and `matplotlib`. +This library requires Python 3.6 or newer. For plotting configurations with the commandline tool `plotcamillaconf`, it also requires `numpy` and `matplotlib`. These are not required for using only with the web interface. These are the names of the packages needed: -| Distribution | python | numpy | matplotlib | +| Distribution | python | numpy (optional) | matplotlib (optional) | |--------------|--------|-------|------------| | Fedora | python3 | python3-numpy | python3-matplotlib | | Debian/Raspbian | python3 | python3-numpy | python3-matplotlib | @@ -30,8 +30,11 @@ On macOS use either Anaconda or Homebrew. The Anaconda procedure is the same as For Homebrew, install Python with `brew install python`, after which you can install the needed packages with pip, `pip3 install numpy` etc. -## Plotting a configuration -This library provides the console command `plotcamillaconf`. Once the library is installed, the command should be available in your terminal. + + + +## Plotting a configuration from the command line +This library provides the console command `plotcamillaconf`. Once the library is installed, togehter with the optional dependencies numpy and matplotlib, the command should be available in your terminal. To use it type: ```sh plotcamillaconf /path/to/some/config.yml @@ -40,7 +43,7 @@ plotcamillaconf /path/to/some/config.yml This will plot the frequency response of all the defined filters, and show a block diagram of the pipeline. -## Evaluating filters +## Plotting filters To plot the frequency response of a filter, use the function `plot_filter`. This is mostly meant for internal use by the `plotcamillaconf` command. ```python plot_filter(filterconf, name=None, samplerate=44100, npoints=1000, toimage=False) @@ -51,7 +54,7 @@ It's also possible to plot the combined frequency response of a Filter step in t ```python plot_filterstep(conf, pipelineindex, name="filterstep", npoints=1000, toimage=False) ``` -This command takes the full configuration as `conf` must be provided. This will plot the step with index `pipelineindex` in the pipeline where 0 is the first step. The `name` is used for the plot title. The number of points in the plot is set with `npoints`. If `toimage` is set to True, then it will instead return the plot as an svg image. +This command takes a full configuration as `conf`. It will then plot the step with index `pipelineindex` in the pipeline where 0 is the first step. The `name` is used for the plot title. The number of points in the plot is set with `npoints`. If `toimage` is set to True, then it will instead return the plot as an svg image. ## Plotting the pipeline To plot a block diagram of the pipeline, use the function `plot_pipeline`. This is mostly meant for internal use by the `plotcamillaconf` command. @@ -60,3 +63,16 @@ plot_pipeline(conf, toimage=False) ``` This takes a full CamillaDSP configuration, `conf`. It will then plot the pipeline using PyPlot. If `toimage` is set to True, then it will instead return the plot as an svg image. +## Evaluating filters +To evaluate the frequency response of a filter, use the function `eval_filter`. This is mostly meant for internal use by the `plotcamillaconf` command as well as the web gui. +```python +eval_filter(filterconf, name=None, samplerate=44100, npoints=1000) +``` +This will evaluate the filter and return the result as a dictionary. The filter configuration `filterconf` must be provided. The `samplerate` defaults to 44100 if not given. The filter `name` is used for labels. The number of points in the plot is set with `npoints`. The contents of the returned dictionary depends on the filter type. A Biquad returns `name`, `samplerate`, `f`, `magnitude` and `phase`. A Conv filter additionally return the impulse response in `time` and `impulse`. + +It's also possible to evaluate the combined frequency response of a Filter step in the pipeline. +```python +eval_filterstep(conf, pipelineindex, name="filterstep", npoints=1000) +``` +This command takes a full configuration as `conf`. It will evaluate the step with index `pipelineindex` in the pipeline where 0 is the first step. As for eval_filter, the result is returned as a dictionary with the same fields as for a Biquad. + diff --git a/camilladsp_plot/eval_filterconfig.py b/camilladsp_plot/eval_filterconfig.py index e58e1d2..f86b141 100644 --- a/camilladsp_plot/eval_filterconfig.py +++ b/camilladsp_plot/eval_filterconfig.py @@ -12,9 +12,9 @@ def logspace(minval, maxval, npoints): def eval_filter(filterconf, name=None, samplerate=44100, npoints=1000): fvect = logspace(1.0, samplerate*0.95/2.0, npoints) - result = {"name": name, "samplerate": samplerate, "f": fvect } if name is None: name = "unnamed {}".format(filterconf['type']) + result = {"name": name, "samplerate": samplerate, "f": fvect } if filterconf['type'] in ('Biquad', 'DiffEq', 'BiquadCombo'): if filterconf['type'] == 'DiffEq': currfilt = DiffEq(filterconf['parameters'], samplerate) diff --git a/setup.py b/setup.py index d1355d9..f269cb6 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="camilladsp_plot", - version="0.3.0", + version="0.4.0", author="Henrik Enquist", author_email="henrik.enquist@gmail.com", description="A library for plotting configs and filters for CamillaDSP", diff --git a/tests/test_filtereval.py b/tests/test_filtereval.py index 59eaf4a..51feb94 100644 --- a/tests/test_filtereval.py +++ b/tests/test_filtereval.py @@ -1,12 +1,9 @@ import pytest -from camilladsp_plot import filter_eval +from camilladsp_plot import filters import numpy as np -def test_24bit(): - filt = filter_eval.Conv(None, 44100) - vect = np.asarray([1, 0, 0, 255, 0, 0, 0, 0, 1], dtype=np.uint8) - expected = np.array([2**16, -2**16, 1]) - new_vect = filt._repack_24bit(vect) - assert abs(np.sum(new_vect-expected))<1e-15 +def test_conv(): + filt = filters.Conv(None, 44100) + # TODO make proper tests