Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! # biquad
2 //!
3 //! `biquad` is a library for creating second order IIR filters for signal processing based on
4 //! [Biquads](https://en.wikipedia.org/wiki/Digital_biquad_filter). Both a
5 //! Direct Form 1 (DF1) and Direct Form 2 Transposed (DF2T) implementation is
6 //! available, where the DF1 is better used when the filter needs retuning
7 //! online, as it has the property to introduce minimal artifacts under retuning,
8 //! while the DF2T is best used for static filters as it has the least
9 //! computational complexity and best numerical stability.
10 //!
11 //! # Examples
12 //!
13 //! ```
14 //! fn main() {
15 //! use biquad::*;
16 //!
17 //! // Cutoff and sampling frequencies
18 //! let f0 = 10.hz();
19 //! let fs = 1.khz();
20 //!
21 //! // Create coefficients for the biquads
22 //! let coeffs = Coefficients::<f32>::from_params(Type::LowPass, fs, f0, Q_BUTTERWORTH_F32).unwrap();
23 //!
24 //! // Create two different biquads
25 //! let mut biquad1 = DirectForm1::<f32>::new(coeffs);
26 //! let mut biquad2 = DirectForm2Transposed::<f32>::new(coeffs);
27 //!
28 //! let input_vec = vec![0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
29 //! let mut output_vec1 = Vec::new();
30 //! let mut output_vec2 = Vec::new();
31 //!
32 //! // Run for all the inputs
33 //! for elem in input_vec {
34 //! output_vec1.push(biquad1.run(elem));
35 //! output_vec2.push(biquad2.run(elem));
36 //! }
37 //! }
38 //! ```
39 //!
40 //! # Errors
41 //!
42 //! `Coefficients::from_params(...)` can error if the cutoff frequency does not adhere to the
43 //! [Nyquist Frequency](https://en.wikipedia.org/wiki/Nyquist_frequency), or if the Q value is
44 //! negative.
45 //!
46 //! `Hertz::from_hz(...)` and `Hertz::from_dt(...)` will error if the frequency is negative.
47 //!
48 //! # Panics
49 //!
50 //! `x.hz()`, `x.khz()`, `x.mhz()`, `x.dt()` will panic for `f32`/`f64` if they are negative.
51 //!
52
53 #![no_std]
54
55 pub mod coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/;
56 pub mod frequencyrust-analyzer cargo biquad 0.4.2 frequency/;
57
58 pub use craterust-analyzer cargo biquad 0.4.2 crate/::coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/::*;
59 pub use craterust-analyzer cargo biquad 0.4.2 crate/::frequencyrust-analyzer cargo biquad 0.4.2 frequency/::*;
60
61 /// The required functions of a biquad implementation
62 pub trait Biquadrust-analyzer cargo biquad 0.4.2 Biquad#<T> {
63 /// A single iteration of a biquad, applying the filtering on the input
64 fn runrust-analyzer cargo biquad 0.4.2 Biquad#run().(&mut self, input: T) -> T;
65
66 /// Updating of coefficients
67 fn update_coefficientsrust-analyzer cargo biquad 0.4.2 Biquad#update_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<T>);
68
69 /// Updating coefficients and returning the old ones. This is useful to avoid deallocating on the audio thread, since
70 /// the `Coefficients` can then be sent to another thread for deallocation.
71 fn replace_coefficientsrust-analyzer cargo biquad 0.4.2 Biquad#replace_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<T>) -> Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<T>;
72
73 /// Set the internal state of the biquad to 0 without allocation.
74 fn reset_staterust-analyzer cargo biquad 0.4.2 Biquad#reset_state().(&mut self);
75 }
76
77 /// Possible errors
78 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
79 pub enum Errorsrust-analyzer cargo biquad 0.4.2 Errors# {
80 OutsideNyquistrust-analyzer cargo biquad 0.4.2 Errors#OutsideNyquist#,
81 NegativeQrust-analyzer cargo biquad 0.4.2 Errors#NegativeQ#,
82 NegativeFrequencyrust-analyzer cargo biquad 0.4.2 Errors#NegativeFrequency#,
83 }
84
85 /// Internal states and coefficients of the Direct Form 1 form
86 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
87 pub struct DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1#<T> {
88 y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1.: T,
89 y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2.: T,
90 x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1.: T,
91 x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2.: T,
92 coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs.: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<T>,
93 }
94
95 /// Internal states and coefficients of the Direct Form 2 Transposed form
96 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
97 pub struct DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#<T> {
98 pub s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1.: T,
99 pub s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2.: T,
100 coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs.: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<T>,
101 }
102
103 impl DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1#<f32> {
104 /// Creates a Direct Form 1 biquad from a set of filter coefficients
105 pub fn newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`]new().(coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32>) -> Selfrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`] {
106 DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1# {
107 y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1.: 0.0_f32,
108 y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2.: 0.0_f32,
109 x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1.: 0.0_f32,
110 x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2.: 0.0_f32,
111 coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs.: coefficients,
112 }
113 }
114 }
115
116 impl Biquadrust-analyzer cargo biquad 0.4.2 Biquad#<f32> for DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1#<f32> {
117 fn runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`][`Biquad<f32>`]run().(&mut self, input: f32) -> f32 {
118 let out = self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..b0rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().input rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..b1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..b2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().self.x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2.
119 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..a1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1.
120 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..a2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().self.y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2.;
121
122 self.x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2. = self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1.;
123 self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1. = input;
124 self.y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2. = self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1.;
125 self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1. = out;
126
127 out
128 }
129
130 fn update_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`][`Biquad<f32>`]update_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32>) {
131 self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs. = new_coefficients;
132 }
133
134 fn replace_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`][`Biquad<f32>`]replace_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32>) -> Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32> {
135 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs., new_coefficients)
136 }
137
138 fn reset_staterust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`][`Biquad<f32>`]reset_state().(&mut self) {
139 self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1. = 0.;
140 self.x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2. = 0.;
141 self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1. = 0.;
142 self.y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2. = 0.;
143 }
144 }
145
146 impl DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1#<f64> {
147 /// Creates a Direct Form 1 biquad from a set of filter coefficients
148 pub fn newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`]new().(coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64>) -> Selfrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`] {
149 DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1# {
150 y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1.: 0.0_f64,
151 y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2.: 0.0_f64,
152 x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1.: 0.0_f64,
153 x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2.: 0.0_f64,
154 coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs.: coefficients,
155 }
156 }
157 }
158
159 impl Biquadrust-analyzer cargo biquad 0.4.2 Biquad#<f64> for DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1#<f64> {
160 fn runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`][`Biquad<f64>`]run().(&mut self, input: f64) -> f64 {
161 let out = self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..b0rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().input rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..b1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..b2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().self.x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2.
162 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..a1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1.
163 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs..a2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().self.y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2.;
164
165 self.x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2. = self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1.;
166 self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1. = input;
167 self.y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2. = self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1.;
168 self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1. = out;
169
170 out
171 }
172
173 fn update_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`][`Biquad<f64>`]update_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64>) {
174 self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs. = new_coefficients;
175 }
176
177 fn replace_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`][`Biquad<f64>`]replace_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64>) -> Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64> {
178 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm1#coeffs., new_coefficients)
179 }
180
181 fn reset_staterust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`][`Biquad<f64>`]reset_state().(&mut self) {
182 self.x1rust-analyzer cargo biquad 0.4.2 DirectForm1#x1. = 0.;
183 self.x2rust-analyzer cargo biquad 0.4.2 DirectForm1#x2. = 0.;
184 self.y1rust-analyzer cargo biquad 0.4.2 DirectForm1#y1. = 0.;
185 self.y2rust-analyzer cargo biquad 0.4.2 DirectForm1#y2. = 0.;
186 }
187 }
188
189 impl DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#<f32> {
190 /// Creates a Direct Form 2 Transposed biquad from a set of filter coefficients
191 pub fn newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`]new().(coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32>) -> Selfrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`] {
192 DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed# {
193 s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1.: 0.0_f32,
194 s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2.: 0.0_f32,
195 coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs.: coefficients,
196 }
197 }
198 }
199
200 impl Biquadrust-analyzer cargo biquad 0.4.2 Biquad#<f32> for DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#<f32> {
201 fn runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`][`Biquad<f32>`]run().(&mut self, input: f32) -> f32 {
202 let out = self.s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..b0rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().input;
203 self.s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1. = self.s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..b1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().input rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..a1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().out;
204 self.s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2. = self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..b2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().input rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..a2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().out;
205
206 out
207 }
208
209 fn update_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`][`Biquad<f32>`]update_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32>) {
210 self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs. = new_coefficients;
211 }
212
213 fn replace_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`][`Biquad<f32>`]replace_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32>) -> Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f32> {
214 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs., new_coefficients)
215 }
216
217 fn reset_staterust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`][`Biquad<f32>`]reset_state().(&mut self) {
218 self.s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1. = 0.;
219 self.s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2. = 0.;
220 }
221 }
222
223 impl DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#<f64> {
224 /// Creates a Direct Form 2 Transposed biquad from a set of filter coefficients
225 pub fn newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`]new().(coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64>) -> Selfrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`] {
226 DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed# {
227 s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1.: 0.0_f64,
228 s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2.: 0.0_f64,
229 coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs.: coefficients,
230 }
231 }
232 }
233
234 impl Biquadrust-analyzer cargo biquad 0.4.2 Biquad#<f64> for DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#<f64> {
235 fn runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`][`Biquad<f64>`]run().(&mut self, input: f64) -> f64 {
236 let out = self.s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..b0rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().input;
237 self.s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1. = self.s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..b1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().input rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..a1rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().out;
238 self.s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2. = self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..b2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#b2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().input rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs..a2rust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#a2. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().out;
239
240 out
241 }
242
243 fn update_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`][`Biquad<f64>`]update_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64>) {
244 self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs. = new_coefficients;
245 }
246
247 fn replace_coefficientsrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`][`Biquad<f64>`]replace_coefficients().(&mut self, new_coefficients: Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64>) -> Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#<f64> {
248 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.coeffsrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#coeffs., new_coefficients)
249 }
250
251 fn reset_staterust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`][`Biquad<f64>`]reset_state().(&mut self) {
252 self.s1rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s1. = 0.;
253 self.s2rust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#s2. = 0.;
254 }
255 }
256
257
258 #[cfg(test)]
259 #[macro_use]
260 extern crate stdrust-analyzer cargo biquad 0.4.2 std/;
261
262 #[cfg(test)]
263 mod testsrust-analyzer cargo biquad 0.4.2 tests/ {
264 use craterust-analyzer cargo biquad 0.4.2 crate/::*;
265
266 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
267 fn test_frequency_f32rust-analyzer cargo biquad 0.4.2 tests/test_frequency_f32().() {
268 let f1 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]hz().();
269 let f2 = 10.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]khz().();
270 let f3 = 10.mhzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]mhz().();
271 let f4 = 10.dtrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]dt().();
272
273 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f1, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f32>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f32>`]from_hz().(10.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
274 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f2, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f32>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f32>`]from_hz().(10000.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
275 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f3, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f32>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f32>`]from_hz().(10000000.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
276 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f4, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f32>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f32>`]from_hz().(0.1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
277
278 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f1 <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). f2);
279 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f3 >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). f2);
280 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f1 == f1);
281 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f1 != f2);
282 }
283
284 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
285 fn test_frequency_f64rust-analyzer cargo biquad 0.4.2 tests/test_frequency_f64().() {
286 let f1 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]hz().();
287 let f2 = 10.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]khz().();
288 let f3 = 10.mhzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]mhz().();
289 let f4 = 10.dtrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]dt().();
290
291 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f1, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f64>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f64>`]from_hz().(10.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
292 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f2, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f64>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f64>`]from_hz().(10000.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
293 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f3, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f64>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f64>`]from_hz().(10000000.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
294 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f4, Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f64>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f64>`]from_hz().(0.1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
295
296 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f1 <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). f2);
297 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f3 >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). f2);
298 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f1 == f1);
299 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f1 != f2);
300 }
301
302 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
303 #[should_panic]
304 fn test_frequency_panicrust-analyzer cargo biquad 0.4.2 tests/test_frequency_panic().() {
305 let _f1 = (-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().10.0).hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[f64][`ToHertz<Self>`]hz().();
306 }
307
308 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
309 fn test_hertz_from_f32rust-analyzer cargo biquad 0.4.2 tests/test_hertz_from_f32().() {
310 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
311 Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f32>::from_dtrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f32>`]from_dt().(1.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
312 Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f32>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f32>`]from_hz().(1.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
313 );
314 }
315
316 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
317 fn test_hertz_from_f64rust-analyzer cargo biquad 0.4.2 tests/test_hertz_from_f64().() {
318 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
319 Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f64>::from_dtrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f64>`]from_dt().(1.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
320 Hertzrust-analyzer cargo biquad 0.4.2 frequency/Hertz#::<f64>::from_hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[`Hertz<f64>`]from_hz().(1.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
321 );
322 }
323
324 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
325 fn test_coefficients_normal_f32rust-analyzer cargo biquad 0.4.2 tests/test_coefficients_normal_f32().() {
326 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]hz().();
327 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]khz().();
328
329 let coeffs = Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f32>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f32>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, fs, f0, Q_BUTTERWORTH_F32rust-analyzer cargo biquad 0.4.2 coefficients/Q_BUTTERWORTH_F32.);
330
331 match coeffs {
332 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {}
333 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => {
334 panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("Coefficients creation failed!");
335 }
336 }
337 }
338
339 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
340 fn test_coefficients_normal_f64rust-analyzer cargo biquad 0.4.2 tests/test_coefficients_normal_f64().() {
341 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]hz().();
342 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]khz().();
343
344 let coeffs = Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f64>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f64>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, fs, f0, Q_BUTTERWORTH_F64rust-analyzer cargo biquad 0.4.2 coefficients/Q_BUTTERWORTH_F64.);
345
346 match coeffs {
347 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {}
348 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => {
349 panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("Coefficients creation failed!");
350 }
351 }
352 }
353
354 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
355 fn test_coefficients_fail_flipped_frequencies_f32rust-analyzer cargo biquad 0.4.2 tests/test_coefficients_fail_flipped_frequencies_f32().() {
356 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]hz().();
357 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]khz().();
358
359 let coeffs = Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f32>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f32>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, f0, fs, Q_BUTTERWORTH_F32rust-analyzer cargo biquad 0.4.2 coefficients/Q_BUTTERWORTH_F32.);
360
361 match coeffs {
362 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {
363 panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("Should not come here");
364 }
365 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
366 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e, Errorsrust-analyzer cargo biquad 0.4.2 Errors#::OutsideNyquistrust-analyzer cargo biquad 0.4.2 Errors#OutsideNyquist#);
367 }
368 }
369 }
370
371 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
372 fn test_coefficients_fail_flipped_frequencies_f64rust-analyzer cargo biquad 0.4.2 tests/test_coefficients_fail_flipped_frequencies_f64().() {
373 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]hz().();
374 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]khz().();
375
376 let coeffs = Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f64>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f64>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, f0, fs, Q_BUTTERWORTH_F64rust-analyzer cargo biquad 0.4.2 coefficients/Q_BUTTERWORTH_F64.);
377
378 match coeffs {
379 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {
380 panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("Should not come here");
381 }
382 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
383 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e, Errorsrust-analyzer cargo biquad 0.4.2 Errors#::OutsideNyquistrust-analyzer cargo biquad 0.4.2 Errors#OutsideNyquist#);
384 }
385 }
386 }
387
388 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
389 fn test_coefficients_fail_negative_q_f32rust-analyzer cargo biquad 0.4.2 tests/test_coefficients_fail_negative_q_f32().() {
390 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]hz().();
391 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]khz().();
392
393 let coeffs = Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f32>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f32>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, fs, f0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().1.0);
394
395 match coeffs {
396 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {
397 panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("Should not come here");
398 }
399 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
400 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e, Errorsrust-analyzer cargo biquad 0.4.2 Errors#::NegativeQrust-analyzer cargo biquad 0.4.2 Errors#NegativeQ#);
401 }
402 }
403 }
404
405 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
406 fn test_coefficients_fail_negative_q_f64rust-analyzer cargo biquad 0.4.2 tests/test_coefficients_fail_negative_q_f64().() {
407 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]hz().();
408 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]khz().();
409
410 let coeffs = Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f64>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f64>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, fs, f0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0);
411
412 match coeffs {
413 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => {
414 panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("Should not come here");
415 }
416 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
417 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e, Errorsrust-analyzer cargo biquad 0.4.2 Errors#::NegativeQrust-analyzer cargo biquad 0.4.2 Errors#NegativeQ#);
418 }
419 }
420 }
421
422 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
423 fn test_biquad_zeros_f32rust-analyzer cargo biquad 0.4.2 tests/test_biquad_zeros_f32().() {
424 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#;
425 //use std::vec::Vec::*;
426
427 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]hz().();
428 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f32>`]khz().();
429
430 let coeffs =
431 Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f32>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f32>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, fs, f0, Q_BUTTERWORTH_F32rust-analyzer cargo biquad 0.4.2 coefficients/Q_BUTTERWORTH_F32.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
432
433 let mut biquad1 = DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1#::<f32>::newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`]new().(coeffs);
434 let mut biquad2 = DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#::<f32>::newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`]new().(coeffs);
435
436 let input_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
437 let mut output_vec1 = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
438 let mut output_vec2 = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
439
440 for elem in input_vec {
441 output_vec1.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(biquad1.runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f32>`][`Biquad<f32>`]run().(elem));
442 output_vec2.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(biquad2.runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f32>`][`Biquad<f32>`]run().(elem));
443 }
444 }
445
446 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
447 fn test_biquad_zeros_f64rust-analyzer cargo biquad 0.4.2 tests/test_biquad_zeros_f64().() {
448 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#;
449 //use std::vec::Vec::*;
450
451 let f0 = 10.hzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]hz().();
452 let fs = 1.khzrust-analyzer cargo biquad 0.4.2 frequency/impl#[i32][`ToHertz<f64>`]khz().();
453
454 let coeffs =
455 Coefficientsrust-analyzer cargo biquad 0.4.2 coefficients/Coefficients#::<f64>::from_paramsrust-analyzer cargo biquad 0.4.2 coefficients/impl#[`Coefficients<f64>`]from_params().(Typerust-analyzer cargo biquad 0.4.2 coefficients/Type#::LowPassrust-analyzer cargo biquad 0.4.2 coefficients/Type#LowPass#, fs, f0, Q_BUTTERWORTH_F64rust-analyzer cargo biquad 0.4.2 coefficients/Q_BUTTERWORTH_F64.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
456
457 let mut biquad1 = DirectForm1rust-analyzer cargo biquad 0.4.2 DirectForm1#::<f64>::newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`]new().(coeffs);
458 let mut biquad2 = DirectForm2Transposedrust-analyzer cargo biquad 0.4.2 DirectForm2Transposed#::<f64>::newrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`]new().(coeffs);
459
460 let input_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
461 let mut output_vec1 = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
462 let mut output_vec2 = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
463
464 for elem in input_vec {
465 output_vec1.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(biquad1.runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm1<f64>`][`Biquad<f64>`]run().(elem));
466 output_vec2.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(biquad2.runrust-analyzer cargo biquad 0.4.2 impl#[`DirectForm2Transposed<f64>`][`Biquad<f64>`]run().(elem));
467 }
468 }
469 }