biquad 0.3__py3-none-any.whl → 0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
biquad/peak.py CHANGED
@@ -6,7 +6,7 @@ SPDX-License-Identifier: MIT
6
6
  Source: https://github.com/jurihock/biquad
7
7
  """
8
8
 
9
- from .biquad import biquad, __df1__
9
+ from .biquad import biquad, __df1__, __gain__, __resize__
10
10
 
11
11
  import numba
12
12
  import numpy
@@ -17,7 +17,7 @@ class peak(biquad):
17
17
  Peaking EQ filter.
18
18
  """
19
19
 
20
- def __init__(self, sr, gain=6, *, f=None, q=1):
20
+ def __init__(self, sr, f=None, g=6, q=1):
21
21
  """
22
22
  Create a new filter instance.
23
23
 
@@ -25,22 +25,21 @@ class peak(biquad):
25
25
  ----------
26
26
  sr : int or float
27
27
  Sample rate in hertz.
28
- gain : int or float, optional
29
- Filter peak gain value in decibel.
30
28
  f : int or float, optional
31
29
  Persistent filter frequency parameter in hertz.
30
+ g : int or float, optional
31
+ Persistent filter gain parameter in decibel.
32
32
  q : int or float, optional
33
33
  Persistent filter quality parameter.
34
34
  """
35
35
 
36
- super().__init__(sr=sr, f=f, q=q)
36
+ super().__init__(sr=sr, f=f, g=g, q=q)
37
37
 
38
- self.gain = gain
39
- self.amp = 10 ** (gain / 40)
38
+ self.g = __gain__(g, 40)
40
39
 
41
- self.__call__(0, 1) # warmup numba
40
+ self.__call__(0) # warmup numba
42
41
 
43
- def __call__(self, x, f=None, q=None):
42
+ def __call__(self, x, f=None, g=None, q=None):
44
43
  """
45
44
  Process single or multiple contiguous signal values at once.
46
45
 
@@ -50,6 +49,8 @@ class peak(biquad):
50
49
  Filter input data.
51
50
  f : scalar or array like, optional
52
51
  Instantaneous filter frequency parameter in hertz.
52
+ g : scalar or array like, optional
53
+ Instantaneous filter gain parameter in decibel.
53
54
  q : scalar or array like, optional
54
55
  Instantaneous filter quality parameter.
55
56
 
@@ -67,22 +68,23 @@ class peak(biquad):
67
68
  x = numpy.atleast_1d(x)
68
69
  y = numpy.zeros(x.shape, x.dtype)
69
70
 
70
- f = numpy.atleast_1d(self.f if f is None else f)
71
- q = numpy.atleast_1d(self.q if q is None else q)
72
-
73
- f = numpy.resize(f, x.shape)
74
- q = numpy.resize(q, x.shape)
71
+ f = __resize__(self.f if f is None else f, x.shape)
72
+ g = __resize__(self.g if g is None else __gain__(g, 40), x.shape)
73
+ q = __resize__(self.q if q is None else q, x.shape)
75
74
 
76
75
  sr = self.sr
77
- amp = self.amp
78
76
 
79
- self.__filter__(ba, xy, x, y, f, q, sr, amp)
77
+ self.__filter__(ba, xy, x, y, f, g, q, sr)
78
+
79
+ self.f = f[-1]
80
+ self.g = g[-1]
81
+ self.q = q[-1]
80
82
 
81
83
  return y[0] if scalar else y
82
84
 
83
85
  @staticmethod
84
86
  @numba.jit(nopython=True, fastmath=True)
85
- def __filter__(ba, xy, x, y, f, q, sr, amp):
87
+ def __filter__(ba, xy, x, y, f, g, q, sr):
86
88
 
87
89
  rs = 2 * numpy.pi / sr
88
90
 
@@ -93,21 +95,19 @@ class peak(biquad):
93
95
  cosw = numpy.cos(w)
94
96
  sinw = numpy.sin(w)
95
97
 
96
- c = -(2 * cosw)
97
- p = sinw / (2 * q[i])
98
-
99
- m = p * amp
100
- d = p / amp
98
+ alpha = sinw / (+2 * q[i])
99
+ beta = cosw * (-2)
100
+ gamma = 1 / g[i]
101
101
 
102
102
  # update b
103
- ba[0, 0] = 1 + m
104
- ba[0, 1] = c
105
- ba[0, 2] = 1 - m
103
+ ba[0, 0] = gamma + alpha
104
+ ba[0, 1] = gamma * beta
105
+ ba[0, 2] = gamma - alpha
106
106
 
107
107
  # update a
108
- ba[1, 0] = 1 + d
109
- ba[1, 1] = c
110
- ba[1, 2] = 1 - d
108
+ ba[1, 0] = 1 + alpha * gamma
109
+ ba[1, 1] = beta
110
+ ba[1, 2] = 1 - alpha * gamma
111
111
 
112
112
  # update y
113
- __df1__(ba, xy, x, y, i)
113
+ __df1__(g[i], ba, xy, x, y, i)
@@ -1,88 +1,103 @@
1
- Metadata-Version: 2.1
2
- Name: biquad
3
- Version: 0.3
4
- Summary: Collection of alterable digital biquad filters for dynamic audio effect creation
5
- Home-page: https://github.com/jurihock/biquad
6
- Author: Juergen Hock
7
- Author-email: juergen.hock@jurihock.de
8
- License: MIT
9
- Keywords: digital,audio,signal,processing,dasp,dafx,effects,filter,equalizer,eq,biquad,frequency,phase,spectrum,algorithms,analysis,synthesis,c,cpp,python
10
- Classifier: Intended Audience :: Developers
11
- Classifier: Intended Audience :: Education
12
- Classifier: Intended Audience :: Other Audience
13
- Classifier: Intended Audience :: Science/Research
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Programming Language :: C
16
- Classifier: Programming Language :: C++
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Topic :: Artistic Software
19
- Classifier: Topic :: Education
20
- Classifier: Topic :: Multimedia :: Sound/Audio
21
- Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
22
- Classifier: Topic :: Multimedia :: Sound/Audio :: Sound Synthesis
23
- Classifier: Topic :: Scientific/Engineering
24
- Classifier: Topic :: Software Development :: Libraries
25
- Requires-Python: >=3
26
- Description-Content-Type: text/markdown
27
- License-File: LICENSE
28
- Requires-Dist: numba
29
- Requires-Dist: numpy
30
-
31
- # Alterable biquad filters
32
-
33
- ![language](https://img.shields.io/badge/languages-C%2B%2B%20Python-blue)
34
- ![license](https://img.shields.io/github/license/jurihock/biquad?color=green)
35
- ![pypi](https://img.shields.io/pypi/v/biquad?color=gold)
36
-
37
- This is a collection of digital biquad filters whose parameters `frequency` and `quality` can be varied at runtime. Following filter implementations are available:
38
-
39
- - Allpass
40
- - Bandpass
41
- - Highpass
42
- - Lowpass
43
- - Highshelf
44
- - Lowshelf
45
- - Notch
46
- - Peak
47
-
48
- ## Basic usage
49
-
50
- Filter with persistent configuration:
51
-
52
- ```python
53
- import biquad
54
- import numpy as np
55
-
56
- # load audio samples somehow
57
- x, sr = np.zeros(...), 44100
58
-
59
- # create a filter of your choice
60
- f = biquad.bandpass(sr, f=sr/4, q=1)
61
-
62
- # process all audio samples
63
- y = f(x)
64
- ```
65
-
66
- Filter with dynamic configuration:
67
-
68
- ```python
69
- import biquad
70
- import numpy as np
71
-
72
- # load audio samples somehow
73
- x, sr = np.zeros(...), 44100
74
-
75
- # create a filter of your choice
76
- f = biquad.bandpass(sr)
77
-
78
- # create parameter modifications as you like
79
- myf = np.linspace(1, sr/4, len(x))
80
- myq = np.linspace(2, 1/2, len(x))
81
-
82
- # process all audio samples
83
- y = f(x, f=myf, q=myq)
84
- ```
85
-
86
- ## See also
87
-
88
- [Cookbook formulae for audio equalizer biquad filter coefficients](https://webaudio.github.io/Audio-EQ-Cookbook/audio-eq-cookbook.html)
1
+ Metadata-Version: 2.4
2
+ Name: biquad
3
+ Version: 0.5
4
+ Summary: Collection of alterable digital biquad filters for dynamic audio effect creation
5
+ Home-page: https://github.com/jurihock/biquad
6
+ Author: Juergen Hock
7
+ Author-email: juergen.hock@jurihock.de
8
+ License: MIT
9
+ Keywords: digital,audio,signal,processing,dasp,dafx,effects,filter,equalizer,eq,biquad,frequency,phase,spectrum,algorithms,analysis,synthesis,c,cpp,python
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Education
12
+ Classifier: Intended Audience :: Other Audience
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: C
16
+ Classifier: Programming Language :: C++
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Artistic Software
19
+ Classifier: Topic :: Education
20
+ Classifier: Topic :: Multimedia :: Sound/Audio
21
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
22
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Sound Synthesis
23
+ Classifier: Topic :: Scientific/Engineering
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ Requires-Python: >=3
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numba
29
+ Requires-Dist: numpy
30
+ Provides-Extra: plot
31
+ Requires-Dist: matplotlib; extra == "plot"
32
+ Dynamic: license-file
33
+
34
+ # Alterable biquad filters
35
+
36
+ ![language](https://img.shields.io/badge/languages-C%2B%2B%20Python-blue)
37
+ ![license](https://img.shields.io/github/license/jurihock/biquad?color=green)
38
+ ![pypi](https://img.shields.io/pypi/v/biquad?color=gold)
39
+
40
+ This is a collection of [digital biquad filters](https://webaudio.github.io/Audio-EQ-Cookbook/audio-eq-cookbook.html) whose parameters `f` (frequency in *Hz*), `g` (gain in *dB*) and `q` (quality) can be varied at runtime. Following [DF1](https://ccrma.stanford.edu/~jos/fp/Direct_Form_I.html) filter implementations are available:
41
+
42
+ - Allpass
43
+ - Bandpass
44
+ - Highpass
45
+ - Lowpass
46
+ - Highshelf
47
+ - Lowshelf
48
+ - Notch
49
+ - Peak
50
+
51
+ ## Basic usage
52
+
53
+ Filter with static configuration:
54
+
55
+ ```python
56
+ import biquad
57
+ import numpy as np
58
+
59
+ # load audio samples somehow
60
+ x, sr = np.zeros(...), 44100
61
+
62
+ # create a filter of your choice
63
+ f = biquad.bandpass(sr, f=sr/4, q=1)
64
+
65
+ # process all audio samples
66
+ y = f(x)
67
+ ```
68
+
69
+ Filter with dynamic configuration:
70
+
71
+ ```python
72
+ import biquad
73
+ import numpy as np
74
+
75
+ # load audio samples somehow
76
+ x, sr = np.zeros(...), 44100
77
+
78
+ # create a filter of your choice
79
+ f = biquad.bandpass(sr)
80
+
81
+ # create parameter modifications as you like
82
+ myf = np.linspace(1, sr/4, len(x))
83
+ myq = np.linspace(2, 1/2, len(x))
84
+
85
+ # process all audio samples
86
+ y = f(x, f=myf, q=myq)
87
+ ```
88
+
89
+ Keep in mind:
90
+
91
+ - All filters have a default value for the persistent parameters `g` and `q`, which is set in the particular `__init__` method.
92
+ - Parameter `f` must be set either in the `__init__` or in the `__call__` method.
93
+ - The optional instantaneous parameters `f`, `g` and `q`, if specified in the `__call__` method, override the persistent ones.
94
+
95
+ ## References
96
+
97
+ 1. <span id="1">[Cookbook formulae for audio EQ biquad filter coefficients](https://webaudio.github.io/Audio-EQ-Cookbook/audio-eq-cookbook.html) by Robert Bristow-Johnson</span>
98
+ 2. <span id="2">[Introduction to Digital Filters with Audio Applications](https://ccrma.stanford.edu/~jos/filters/filters.html) by Julius O. Smith III</span>
99
+
100
+ ## License
101
+
102
+ [github.com/jurihock/biquad](https://github.com/jurihock/biquad) is licensed under the terms of the MIT license.
103
+ For details please refer to the accompanying [LICENSE](https://github.com/jurihock/biquad/raw/main/LICENSE) file distributed with it.
@@ -0,0 +1,15 @@
1
+ biquad/__init__.py,sha256=lJlcLKlrtWmWduV82lyu7l6C4BEWo_d_yko4tXPsxEs,1421
2
+ biquad/allpass.py,sha256=T9iANDZ-xutExvC8HzBxInT1t0Ns_FUUhzuu3mWpdHk,2813
3
+ biquad/bandpass.py,sha256=n3A3Fgo_b1-ijqh2bp2vQiC4FpxN-vJc-U8gplUjV8Y,3141
4
+ biquad/biquad.py,sha256=0F1A2ITPOi5K53v4b6ZZrCOj1vhW1yJ5N_ctsY7LIa8,7299
5
+ biquad/highpass.py,sha256=xZEZAZ5b50kzs_0yvMAekykrRXiFjxXS3Gv-DB-V5p0,2826
6
+ biquad/highshelf.py,sha256=OefPSr9_sp7wi8iAM_WGY-QwUf63VMmqvUuX7ZuxU5g,3050
7
+ biquad/lowpass.py,sha256=PT02sbclZWVG8IdV7OmlbsTDzHhp2FdLMEKCMkacaKA,2824
8
+ biquad/lowshelf.py,sha256=neHqS1pfz0AcO9SgLn6R1iX5eKI-_-Ly6jseCqGTt6s,3048
9
+ biquad/notch.py,sha256=Cl_aja0m_JMLS6jP5Exo5YsE0N5fB54BmH54k6_hbBQ,2784
10
+ biquad/peak.py,sha256=Rodqhlgr0r63gE5luht5uBN24iczaQ84qPzM4hpoPI0,2905
11
+ biquad-0.5.dist-info/licenses/LICENSE,sha256=JRS0dwoeKyDdxU93F1NzI806Zua2CgWaew0T77hhh1M,1090
12
+ biquad-0.5.dist-info/METADATA,sha256=frNBOBNFGTpZ0ixzcxbiVywwUhzgBueHmlWgDEAbt0Q,3683
13
+ biquad-0.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
14
+ biquad-0.5.dist-info/top_level.txt,sha256=OMpggdHRsGUakoTOYGPJ7qbs8EHjfoB6UqpcKSflty8,7
15
+ biquad-0.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.40.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Juergen Hock
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Juergen Hock
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
biquad/plot.py DELETED
@@ -1,96 +0,0 @@
1
- """
2
- Copyright (c) 2023 Juergen Hock
3
-
4
- SPDX-License-Identifier: MIT
5
-
6
- Source: https://github.com/jurihock/biquad
7
- """
8
-
9
- import numpy
10
-
11
-
12
- def __abs__(x, db=False):
13
-
14
- if db:
15
- with numpy.errstate(divide='ignore', invalid='ignore'):
16
- return 20 * numpy.log10(numpy.abs(x))
17
- else:
18
- return numpy.abs(x)
19
-
20
-
21
- def __arg__(x, wrap=None):
22
-
23
- if wrap is None:
24
- return numpy.angle(x)
25
- elif wrap:
26
- return (numpy.angle(x) + numpy.pi) % (2 * numpy.pi) - numpy.pi
27
- else:
28
- return numpy.unwrap(numpy.angle(x))
29
-
30
-
31
- class plot:
32
-
33
- def __init__(self, w, h):
34
-
35
- self.w = w
36
- self.h = h
37
-
38
- def frequency(self, xlim=None, ylim=None):
39
-
40
- import matplotlib.pyplot as pyplot
41
-
42
- def lim():
43
-
44
- if xlim is not None:
45
- if isinstance(xlim, (list, tuple)):
46
- pyplot.xlim(xlim)
47
- else:
48
- pyplot.xlim(0, xlim)
49
-
50
- if ylim is not None:
51
- if isinstance(ylim, (list, tuple)):
52
- pyplot.ylim(ylim)
53
- else:
54
- pyplot.ylim(ylim, 0)
55
- else:
56
- pyplot.ylim(-110, numpy.maximum(10, y.max()))
57
-
58
- x, y = self.w, __abs__(self.h, db=True)
59
-
60
- pyplot.plot(x, y)
61
- pyplot.xlabel('Hz')
62
- pyplot.ylabel('dB')
63
-
64
- lim()
65
-
66
- return pyplot
67
-
68
- def phase(self, xlim=None, ylim=None):
69
-
70
- import matplotlib.pyplot as pyplot
71
-
72
- def lim():
73
-
74
- if xlim is not None:
75
- if isinstance(xlim, (list, tuple)):
76
- pyplot.xlim(xlim)
77
- else:
78
- pyplot.xlim(0, xlim)
79
-
80
- if ylim is not None:
81
- if isinstance(ylim, (list, tuple)):
82
- pyplot.ylim(ylim)
83
- else:
84
- pyplot.ylim(-ylim, +ylim)
85
- else:
86
- pyplot.ylim(-numpy.pi, +numpy.pi)
87
-
88
- x, y = self.w, __arg__(self.h, wrap=True)
89
-
90
- pyplot.plot(x, y)
91
- pyplot.xlabel('Hz')
92
- pyplot.ylabel('rad')
93
-
94
- lim()
95
-
96
- return pyplot
@@ -1,16 +0,0 @@
1
- biquad/__init__.py,sha256=m8pno1TqDKeAnydyV58xRs6VU7Ji54gzOQpIMZ92th8,1366
2
- biquad/allpass.py,sha256=ftBPy6C0FZ-eWFel4je6Yt__49oF7Xw8fVL-7sXRans,2464
3
- biquad/bandpass.py,sha256=IcADoJHoiEIPeKuNXvFIrbxEm-4I2IgCeoLl6lAz0cE,2782
4
- biquad/biquad.py,sha256=Z-7VSkR2seMRhxCrpUVrnNwrodFcgknNJdCFMCi2eu8,4937
5
- biquad/highpass.py,sha256=toAud4xe_IiXJWH3XZAOi13xBw2SOcGbDc8q3GXgYRA,2488
6
- biquad/highshelf.py,sha256=uTzFtPSNDBl-hcmKtQpOd-khuAjin1LPLbxDyhuhRtw,2766
7
- biquad/lowpass.py,sha256=wD1juxQhHjfE_auYNaATkhoA-5tj7t7HtBOUogahbD8,2486
8
- biquad/lowshelf.py,sha256=4wEePModCtxZLkOYni-DMEgv2XLlr_mcw68fjMsAPBc,2764
9
- biquad/notch.py,sha256=eeoByEyuqrrf8Qdw1ByH3PL9H9SfJTKgMkphfyan8Dk,2443
10
- biquad/peak.py,sha256=c8d6J8zMrjgneD47Yz-hn0Gt5EUhjreTL4G8xzTaD5c,2705
11
- biquad/plot.py,sha256=lcIEmY3B8nbOXqV6viQt787-sh4wRa66XbaeftTs0wU,2089
12
- biquad-0.3.dist-info/LICENSE,sha256=zGdw_6DxFbsP_zfw5mVFVtwkpdfZ2nFql_XpjwBZ7ps,1069
13
- biquad-0.3.dist-info/METADATA,sha256=8h9I-U2HM9T914VRXVe_oUwUKbfohXggmxzwqd7J8eQ,2514
14
- biquad-0.3.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
15
- biquad-0.3.dist-info/top_level.txt,sha256=OMpggdHRsGUakoTOYGPJ7qbs8EHjfoB6UqpcKSflty8,7
16
- biquad-0.3.dist-info/RECORD,,