1"""Module for filter elements
4from typing
import Union
8gi.require_version(
'Gst',
'1.0')
9from gi.repository
import GObject
10from gi.repository
import Gst
15from gstlal
import gstpipetools
16from gstlal.pipeparts
import pipetools
20def audio_cheb_band(pipeline: pipetools.Pipeline, src: pipetools.Element, lower_frequency: float, upper_frequency: float, poles: int = 8) -> pipetools.Element:
21 """Attenuates all frequencies outside (bandpass) or inside (bandreject) of a frequency band. The number
22 of poles and the ripple parameter control the rolloff. This element has the advantage over the windowed
23 sinc bandpass and bandreject filter that it is much faster and produces almost as good results. It's only
24 disadvantages are the highly non-linear phase and the slower rolloff compared to a windowed sinc filter
25 with a large kernel. For type 1 the ripple parameter specifies how much ripple in dB is allowed in the
26 passband, i.e. some frequencies in the passband will be amplified by that value. A higher ripple value
27 will allow a faster rolloff. For type 2 the ripple parameter specifies the stopband attenuation. In the
28 stopband the gain will be at most this value. A lower ripple value will allow a faster rolloff. As a
29 special case, a Chebyshev type 1 filter with no ripple is a Butterworth filter.
33 Gst.Pipeline, the pipeline to which the new element will be added
35 Gst.Element, the source element
37 float, Start frequency of the band (Hz)
39 float, Stop frequency of the band (Hz)
41 int, Number of poles to use, will be rounded up to the next multiple of four
44 [1] https://gstreamer.freedesktop.org/documentation/audiofx/audiochebband.html?gi-language=python
49 return pipetools.make_element_with_src(pipeline, src,
"audiochebband", lower_frequency=lower_frequency, upper_frequency=upper_frequency, poles=poles)
53def audio_cheb_limit(pipeline: pipetools.Pipeline, src: pipetools.Element, cutoff: float, mode: int = 0, poles: int = 8, type: int = 1, ripple: float = 0.25) -> pipetools.Element:
54 """Attenuates all frequencies above the cutoff frequency (low-pass) or all frequencies below the cutoff frequency (high-pass).
55 The number of poles and the ripple parameter control the rolloff. This element has the advantage over the windowed sinc lowpass
56 and highpass filter that it is much faster and produces almost as good results. It's only disadvantages are the highly non-linear
57 phase and the slower rolloff compared to a windowed sinc filter with a large kernel. For type 1 the ripple parameter specifies
58 how much ripple in dB is allowed in the passband, i.e. some frequencies in the passband will be amplified by that value. A higher
59 ripple value will allow a faster rolloff. For type 2 the ripple parameter specifies the stopband attenuation. In the stopband the
60 gain will be at most this value. A lower ripple value will allow a faster rolloff. As a special case, a Chebyshev type 1 filter
61 with no ripple is a Butterworth filter.
65 Gst.Pipeline, the pipeline to which the new element will be added
67 Gst.Element, the source element
69 float, Cut off frequency (Hz)
71 int, default 0, 0 for low-pass or 1 for high-pass
73 int, Number of poles to use, will be rounded up to the next multiple of four
75 int, default 1, Type of the chebychev filter
77 float, default 0,25, Amount of ripple (dB)
80 [1] https://gstreamer.freedesktop.org/documentation/audiofx/audiocheblimit.html?gi-language=python
85 return pipetools.make_element_with_src(pipeline, src,
"audiocheblimit", cutoff=cutoff, mode=mode, poles=poles, type=type, ripple=ripple)
89def caps(pipeline: pipetools.Pipeline, src: pipetools.Element, caps: Union[str, pipetools.Caps], **properties: dict) -> pipetools.Element:
90 """The element does not modify data as such, but can enforce limitations on the data format.
91 Note: this element does *not* act as a filter on the data of the source, but rather as a filter on the
92 metadata (CAPS) of the source element.
96 Gst.Pipeline, the pipeline to which the new element will be added
98 Gst.Element, the source element
100 str or Gst.Caps, the capabilities specification to limit the source data format
102 dict, keyword arguments to be set as element properties
105 [1] capsfilter docs: https://gstreamer.freedesktop.org/documentation/coreelements/capsfilter.html?gi-language=python
108 Element, the source element limited by the given caps (capabilities)
110 return pipetools.make_element_with_src(pipeline, src,
"capsfilter", caps=gstpipetools.to_caps(caps), **properties)
114def drop(pipeline: pipetools.Pipeline, src: pipetools.Element, drop_samples: int = 0) -> pipetools.Element:
115 """Drop samples from the start of a stream
119 Gst.Pipeline, the pipeline to which the new element will be added
121 Iterable[Gst.Element], the source elements
123 int, default 0, number of samples to drop from the beginning of a stream
126 Implementation: gstlal/gst/lal/gstlal_drop.c
131 return pipetools.make_element_with_src(pipeline, src,
"lal_drop", drop_samples=drop_samples)
135def fir(pipeline: pipetools.Pipeline, src: pipetools.Element, kernel: pipetools.GValueArray, latency, **properties: dict) -> pipetools.Element:
136 """Generic audio FIR filter. Before usage the "kernel" property has to be set to the filter kernel that should be
137 used and the "latency" property has to be set to the latency (in samples) that is introduced by the filter kernel.
138 Setting a latency of n samples will lead to the first n samples being dropped from the output and n samples added
141 The filter kernel describes the impulse response of the filter. To calculate the frequency response of the filter
142 you have to calculate the Fourier Transform of the impulse response.
144 To change the filter kernel whenever the sampling rate changes the "rate-changed" signal can be used. This should
145 be done for most FIR filters as they're depending on the sampling rate.
149 Gst.Pipeline, the pipeline to which the new element will be added
151 Gst.Element, the source element
153 Gst.GValueArray, filter kernel for the FIR filter
155 int, filter latency in samples
157 dict, keyword arguments to be set as element properties
160 [1] audiofirfilter docs: https://gstreamer.freedesktop.org/documentation/audiofx/audiofirfilter.html?gi-language=python
163 Element, the FIR element
165 properties.update((name, val)
for name, val
in ((
"kernel", kernel), (
"latency", latency))
if val
is not None)
166 return pipetools.make_element_with_src(pipeline, src,
"audiofirfilter", **properties)
170def gate(pipeline: pipetools.Pipeline, src: pipetools.Element, threshold: float =
None, control: pipetools.Element =
None, **properties) -> pipetools.Element:
171 """Flag buffers as gaps based on the value of a control input
175 Gst.Pipeline, the pipeline to which the new element will be added
177 Gst.Element, the source element
179 float, default None, uutput will be flagged as non-gap when magnitude of control input is >= this value. See also invert-control.
181 Element, optional control element input
184 bool, Emit start and stop signals (rate-changed is always emited). The start and stop signals
185 are emited on gap-to-non-gap and non-gap-to-gap transitions in the output stream respectively.
188 Implementation: gstlal/gst/lal/gstlal_gate.c
193 if threshold
is not None:
194 elem = pipetools.make_element_with_src(pipeline,
None,
"lal_gate", threshold=threshold, **properties)
196 elem = pipetools.make_element_with_src(pipeline,
None,
"lal_gate", **properties)
197 for peer, padname
in ((src,
"sink"), (control,
"control")):
198 if isinstance(peer, Gst.Pad):
199 peer.get_parent_element().link_pads(peer, elem, padname)
200 elif peer
is not None:
201 peer.link_pads(
None, elem, padname)
206def iir(pipeline: pipetools.Pipeline, src: pipetools.Element, a: pipetools.ValueArray, b: pipetools.ValueArray) -> pipetools.Element:
207 """aGeneric audio IIR filter. Before usage the "a" and "b" properties have to be set to the filter coefficients
210 The filter coefficients describe the numerator and denominator of the transfer function.
212 To change the filter coefficients whenever the sampling rate changes the "rate-changed" signal can be used.
213 This should be done for most IIR filters as they're depending on the sampling rate.
215 convention is z = \exp(-i 2 \pi f / f_{\rm sampling})
216 H(z) = (\sum_{j=0}^{N} a_j z^{-j}) / (\sum_{j=0}^{N} (-1)^{j} b_j z^{-j})
220 Gst.Pipeline, the pipeline to which the new element will be added
222 Gst.Element, the source element
224 ValueArray, Filter coefficients (denominator of transfer function)
226 ValueArray, Filter coefficients (numerator of transfer function)
229 [1] audioiirfilter docs: https://gstreamer.freedesktop.org/documentation/audiofx/audioiirfilter.html?gi-language=python
232 Element, IIR of the sources
235 return pipetools.make_element_with_src(pipeline, src,
"audioiirfilter", a=a, b=b)
239def remove_fake_disconts(pipeline: pipetools.Pipeline, src: pipetools.Element, silent: bool =
True) -> pipetools.Element:
240 """Fix incorrectly-set discontinuity flags
244 Gst.Pipeline, the pipeline to which the new element will be added
246 Iterable[Gst.Element], the source elements
248 bool, default True, if True Don't print a message when alterning the flags in a buffer.
251 Implementation: gstal/gst/lal/gstlal_nofakedisconts.c
256 return pipetools.make_element_with_src(pipeline, src,
"lal_nofakedisconts", silent=silent)
260def state_vector(pipeline: pipetools.Pipeline, src: pipetools.Element, **properties) -> pipetools.Element:
261 """Converts a state vector stream into booleans, for example to drive a lal_gate element.
265 Gst.Pipeline, the pipeline to which the new element will be added
267 Gst.Element, the source element
271 Implementation: gstlal/gst/lal/gstlal_statevector.c
276 return pipetools.make_element_with_src(pipeline, src,
"lal_statevector", **properties)
280def inject(pipeline: pipetools.Pipeline, src: pipetools.Element, filename: str) -> pipetools.Element:
281 """An injection routine calling lalsimulation waveform generators
285 Gst.Pipeline, the pipeline to which the new element will be added
287 Gst.Element, the source element
289 str, path to xml file Name of LIGO Light Weight XML file containing list(s) of software injections
292 Implementation: gstlal/gst/lal/gstlal_simulation.c
297 return pipetools.make_element_with_src(pipeline, src,
"lal_simulation", xml_location=filename)
pipetools.Element caps(pipetools.Pipeline pipeline, pipetools.Element src, Union[str, pipetools.Caps] caps, **dict properties)
Adds a capsfilter element to a pipeline with useful default properties.
pipetools.Element gate(pipetools.Pipeline pipeline, pipetools.Element src, float threshold=None, pipetools.Element control=None, **properties)
Adds a lal_gate element to a pipeline with useful default properties.
pipetools.Element drop(pipetools.Pipeline pipeline, pipetools.Element src, int drop_samples=0)
Adds a lal_whiten element to a pipeline with useful default properties.
pipetools.Element state_vector(pipetools.Pipeline pipeline, pipetools.Element src, **properties)
Adds a lal_statevector element to a pipeline with useful default properties.
pipetools.Element remove_fake_disconts(pipetools.Pipeline pipeline, pipetools.Element src, bool silent=True)
Adds a lal_nofakedisconts element to a pipeline with useful default properties.
pipetools.Element inject(pipetools.Pipeline pipeline, pipetools.Element src, str filename)
Adds a lal_simulation element to a pipeline with useful default properties.
pipetools.Element fir(pipetools.Pipeline pipeline, pipetools.Element src, pipetools.GValueArray kernel, latency, **dict properties)
Adds a audiofirfilter element to a pipeline with useful default properties.
pipetools.Element audio_cheb_limit(pipetools.Pipeline pipeline, pipetools.Element src, float cutoff, int mode=0, int poles=8, int type=1, float ripple=0.25)
Adds a audiocheblimit element to a pipeline with useful default properties.
pipetools.Element iir(pipetools.Pipeline pipeline, pipetools.Element src, pipetools.ValueArray a, pipetools.ValueArray b)
Adds a audioiirfilter element to a pipeline with useful default properties.
pipetools.Element audio_cheb_band(pipetools.Pipeline pipeline, pipetools.Element src, float lower_frequency, float upper_frequency, int poles=8)
Adds a audiochebband element to a pipeline with useful default properties.