Skip to content

Commit 2dfb4a3

Browse files
committed
Avoid resetting butterworth
1 parent 99779bf commit 2dfb4a3

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

modules/yup_dsp/filters/yup_ButterworthFilter.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ namespace yup
2525
{
2626

2727
//==============================================================================
28-
/**
28+
/**
2929
Butterworth filter coefficient calculator and implementation.
30-
30+
3131
Butterworth filters provide maximally flat passband response with no ripple
3232
in either passband or stopband. They offer the best phase response among
3333
classical filter types but have the gentlest rolloff.
34-
34+
3535
Features:
3636
- Orders 1-20 supported
3737
- Lowpass, highpass, bandpass, bandstop configurations
3838
- Automatic biquad cascade generation
3939
- Stable coefficient calculation using analog prototypes
40-
40+
4141
@see BiquadCascade, FilterBase
4242
*/
4343
template <typename SampleType, typename CoeffType = double>
@@ -46,7 +46,7 @@ class ButterworthFilter : public FilterBase<SampleType, CoeffType>
4646
public:
4747
//==============================================================================
4848
/** Default constructor */
49-
ButterworthFilter()
49+
ButterworthFilter()
5050
: cascade (1)
5151
{
5252
setParameters (FilterType::lowpass, 2, static_cast<CoeffType> (1000.0), 44100.0);
@@ -94,9 +94,9 @@ class ButterworthFilter : public FilterBase<SampleType, CoeffType>
9494
}
9595

9696
//==============================================================================
97-
/**
97+
/**
9898
Sets all filter parameters.
99-
99+
100100
@param type The filter type (lowpass, highpass, etc.)
101101
@param order The filter order (1-20)
102102
@param frequency The cutoff frequency in Hz (or center frequency for bandpass/bandstop)
@@ -114,17 +114,17 @@ class ButterworthFilter : public FilterBase<SampleType, CoeffType>
114114
const auto numSections = calculateNumSections (filterOrder);
115115
if (cascade.getNumSections() != static_cast<size_t> (numSections))
116116
cascade.setNumSections (numSections);
117-
117+
118118
// Pre-size coefficient storage to avoid allocation during updateCoefficients
119119
if (coefficientsStorage.size() != static_cast<size_t> (numSections))
120120
coefficientsStorage.resize (numSections);
121121

122122
updateCoefficients();
123123
}
124124

125-
/**
125+
/**
126126
Sets just the cutoff frequency.
127-
127+
128128
@param frequency The new cutoff frequency in Hz
129129
*/
130130
void setCutoffFrequency (CoeffType frequency) noexcept
@@ -133,9 +133,9 @@ class ButterworthFilter : public FilterBase<SampleType, CoeffType>
133133
updateCoefficients();
134134
}
135135

136-
/**
136+
/**
137137
Sets just the filter order.
138-
138+
139139
@param order The new filter order (1-20)
140140
*/
141141
void setOrder (int order) noexcept
@@ -146,38 +146,38 @@ class ButterworthFilter : public FilterBase<SampleType, CoeffType>
146146
filterOrder = newOrder;
147147
const auto numSections = calculateNumSections (filterOrder);
148148
cascade.setNumSections (numSections);
149-
149+
150150
// Pre-size coefficient storage to avoid allocation during updateCoefficients
151151
if (coefficientsStorage.size() != static_cast<size_t> (numSections))
152152
coefficientsStorage.resize (numSections);
153-
153+
154154
updateCoefficients();
155155
}
156156
}
157157

158-
/**
158+
/**
159159
Gets the current cutoff frequency.
160-
160+
161161
@returns The cutoff frequency in Hz
162162
*/
163163
CoeffType getCutoffFrequency() const noexcept
164164
{
165165
return cutoffFreq;
166166
}
167167

168-
/**
168+
/**
169169
Gets the current filter order.
170-
170+
171171
@returns The filter order
172172
*/
173173
int getOrder() const noexcept
174174
{
175175
return filterOrder;
176176
}
177177

178-
/**
178+
/**
179179
Gets the current filter type.
180-
180+
181181
@returns The filter type
182182
*/
183183
FilterType getFilterType() const noexcept
@@ -223,23 +223,21 @@ class ButterworthFilter : public FilterBase<SampleType, CoeffType>
223223
FilterDesigner<CoeffType>::designButterworthLowpass (coefficientsStorage, filterOrder, cutoffFreq, this->sampleRate);
224224
break;
225225
}
226-
226+
227227
// Apply coefficients to cascade
228228
for (size_t i = 0; i < coefficientsStorage.size(); ++i)
229229
cascade.setSectionCoefficients (i, coefficientsStorage[i]);
230-
231-
cascade.reset();
232230
}
233231

234232

235233
//==============================================================================
236234
BiquadCascade<SampleType, CoeffType> cascade;
237-
235+
238236
FilterType filterType = FilterType::lowpass;
239237
int filterOrder = 2;
240238
CoeffType cutoffFreq = static_cast<CoeffType> (1000.0);
241239
CoeffType bandwidthOctaves = static_cast<CoeffType> (1.0);
242-
240+
243241
std::vector<BiquadCoefficients<CoeffType>> coefficientsStorage;
244242

245243
//==============================================================================

0 commit comments

Comments
 (0)