Skip to content

Commit dd4acc1

Browse files
committed
More tweaking
1 parent 1c98fff commit dd4acc1

File tree

6 files changed

+160
-96
lines changed

6 files changed

+160
-96
lines changed

examples/graphics/source/examples/FilterDemo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ class FilterDemo
10351035
// Parameter controls
10361036
frequencySlider = std::make_unique<yup::Slider> (yup::Slider::LinearBarHorizontal, "Frequency");
10371037
frequencySlider->setRange ({ 20.0, 20000.0 });
1038-
//frequencySlider->setSkewFactor (0.3); // Logarithmic scale
1038+
frequencySlider->setSkewFactor (0.3); // Logarithmic scale
10391039
frequencySlider->setValue (1000.0);
10401040
frequencySlider->onValueChanged = [this] (float)
10411041
{

modules/yup_dsp/designers/yup_FilterDesigner.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,21 @@ namespace
3333
template <typename CoeffType>
3434
static void transformLowpassToHighpass (BiquadCoefficients<CoeffType>& coeffs) noexcept
3535
{
36-
// Spectral inversion: negate odd-indexed coefficients
37-
coeffs.b1 = -coeffs.b1;
38-
coeffs.a1 = -coeffs.a1;
36+
// Spectral inversion: H_hp(z) = [A(z) - B(z)] / A(z)
37+
auto old_b0 = coeffs.b0;
38+
auto old_b1 = coeffs.b1;
39+
auto old_b2 = coeffs.b2;
40+
auto old_a1 = coeffs.a1;
41+
auto old_a2 = coeffs.a2;
42+
43+
// new numerator = A(z) - B(z)
44+
coeffs.b0 = static_cast<CoeffType>(1) - old_b0;
45+
coeffs.b1 = old_a1 - old_b1;
46+
coeffs.b2 = old_a2 - old_b2;
47+
48+
// denominator stays the same
49+
// coeffs.a1 = old_a1;
50+
// coeffs.a2 = old_a2;
3951
}
4052

4153
//==============================================================================

modules/yup_dsp/designers/yup_FilterDesigner.h

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,98 @@ template <typename CoeffType>
5050
class FilterDesigner
5151
{
5252
public:
53+
//==============================================================================
54+
// FIR Filter Design
55+
//==============================================================================
56+
57+
/**
58+
Designs FIR lowpass filter coefficients using windowing method.
59+
60+
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
61+
@param cutoff The cutoff frequency in Hz
62+
@param sampleRate The sample rate in Hz
63+
@param windowType The window function to use
64+
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
65+
*/
66+
static void designFirLowpass (
67+
std::vector<CoeffType>& coeffs,
68+
CoeffType cutoff,
69+
double sampleRate,
70+
WindowType windowType = WindowType::kaiser,
71+
CoeffType parameter = static_cast<CoeffType> (6.0)
72+
) noexcept
73+
{
74+
designFIRLowpassImpl (coeffs, cutoff, sampleRate);
75+
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
76+
}
77+
78+
/**
79+
Designs FIR highpass filter coefficients using windowing method.
80+
81+
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
82+
@param cutoff The cutoff frequency in Hz
83+
@param sampleRate The sample rate in Hz
84+
@param windowType The window function to use
85+
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
86+
*/
87+
static void designFirHighpass (
88+
std::vector<CoeffType>& coeffs,
89+
CoeffType cutoff,
90+
double sampleRate,
91+
WindowType windowType = WindowType::kaiser,
92+
CoeffType parameter = static_cast<CoeffType> (6.0)
93+
) noexcept
94+
{
95+
designFIRHighpassImpl (coeffs, cutoff, sampleRate);
96+
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
97+
}
98+
99+
/**
100+
Designs FIR bandpass filter coefficients using windowing method.
101+
102+
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
103+
@param lowCutoff The low cutoff frequency in Hz
104+
@param highCutoff The high cutoff frequency in Hz
105+
@param sampleRate The sample rate in Hz
106+
@param windowType The window function to use
107+
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
108+
*/
109+
static void designFirBandpass (
110+
std::vector<CoeffType>& coeffs,
111+
CoeffType lowCutoff,
112+
CoeffType highCutoff,
113+
double sampleRate,
114+
WindowType windowType = WindowType::kaiser,
115+
CoeffType parameter = static_cast<CoeffType> (6.0)
116+
) noexcept
117+
{
118+
designFIRBandpassImpl (coeffs, lowCutoff, highCutoff, sampleRate);
119+
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
120+
}
121+
122+
/**
123+
Designs FIR bandstop filter coefficients using windowing method.
124+
125+
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
126+
@param lowCutoff The low cutoff frequency in Hz
127+
@param highCutoff The high cutoff frequency in Hz
128+
@param sampleRate The sample rate in Hz
129+
@param windowType The window function to use
130+
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
131+
*/
132+
static void designFirBandstop (
133+
std::vector<CoeffType>& coeffs,
134+
CoeffType lowCutoff,
135+
CoeffType highCutoff,
136+
double sampleRate,
137+
WindowType windowType = WindowType::kaiser,
138+
CoeffType parameter = static_cast<CoeffType> (6.0)
139+
) noexcept
140+
{
141+
designFIRBandstopImpl (coeffs, lowCutoff, highCutoff, sampleRate);
142+
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
143+
}
144+
53145
//==============================================================================
54146
// Butterworth Filter Design
55147
//==============================================================================
@@ -422,98 +514,6 @@ class FilterDesigner
422514
}
423515
#endif
424516

425-
//==============================================================================
426-
// FIR Filter Design
427-
//==============================================================================
428-
429-
/**
430-
Designs FIR lowpass filter coefficients using windowing method.
431-
432-
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
433-
@param cutoff The cutoff frequency in Hz
434-
@param sampleRate The sample rate in Hz
435-
@param windowType The window function to use
436-
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
437-
*/
438-
static void designFirLowpass (
439-
std::vector<CoeffType>& coeffs,
440-
CoeffType cutoff,
441-
double sampleRate,
442-
WindowType windowType = WindowType::kaiser,
443-
CoeffType parameter = static_cast<CoeffType> (6.0)
444-
) noexcept
445-
{
446-
designFIRLowpassImpl (coeffs, cutoff, sampleRate);
447-
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
448-
}
449-
450-
/**
451-
Designs FIR highpass filter coefficients using windowing method.
452-
453-
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
454-
@param cutoff The cutoff frequency in Hz
455-
@param sampleRate The sample rate in Hz
456-
@param windowType The window function to use
457-
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
458-
*/
459-
static void designFirHighpass (
460-
std::vector<CoeffType>& coeffs,
461-
CoeffType cutoff,
462-
double sampleRate,
463-
WindowType windowType = WindowType::kaiser,
464-
CoeffType parameter = static_cast<CoeffType> (6.0)
465-
) noexcept
466-
{
467-
designFIRHighpassImpl (coeffs, cutoff, sampleRate);
468-
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
469-
}
470-
471-
/**
472-
Designs FIR bandpass filter coefficients using windowing method.
473-
474-
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
475-
@param lowCutoff The low cutoff frequency in Hz
476-
@param highCutoff The high cutoff frequency in Hz
477-
@param sampleRate The sample rate in Hz
478-
@param windowType The window function to use
479-
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
480-
*/
481-
static void designFirBandpass (
482-
std::vector<CoeffType>& coeffs,
483-
CoeffType lowCutoff,
484-
CoeffType highCutoff,
485-
double sampleRate,
486-
WindowType windowType = WindowType::kaiser,
487-
CoeffType parameter = static_cast<CoeffType> (6.0)
488-
) noexcept
489-
{
490-
designFIRBandpassImpl (coeffs, lowCutoff, highCutoff, sampleRate);
491-
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
492-
}
493-
494-
/**
495-
Designs FIR bandstop filter coefficients using windowing method.
496-
497-
@param coeffs Pre-allocated vector to store coefficients (size determines filter length)
498-
@param lowCutoff The low cutoff frequency in Hz
499-
@param highCutoff The high cutoff frequency in Hz
500-
@param sampleRate The sample rate in Hz
501-
@param windowType The window function to use
502-
@param parameter Window parameter (Kaiser beta, Gaussian sigma, etc.)
503-
*/
504-
static void designFirBandstop (
505-
std::vector<CoeffType>& coeffs,
506-
CoeffType lowCutoff,
507-
CoeffType highCutoff,
508-
double sampleRate,
509-
WindowType windowType = WindowType::kaiser,
510-
CoeffType parameter = static_cast<CoeffType> (6.0)
511-
) noexcept
512-
{
513-
designFIRBandstopImpl (coeffs, lowCutoff, highCutoff, sampleRate);
514-
WindowFunctions<CoeffType>::applyWindow (windowType, coeffs, parameter);
515-
}
516-
517517
//==============================================================================
518518
// RBJ (Audio EQ Cookbook) Filter Design
519519
//==============================================================================

modules/yup_dsp/filters/yup_ButterworthFilter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ class ButterworthFilter : public FilterBase<SampleType, CoeffType>
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();
230232
}
231233

232234

modules/yup_gui/widgets/yup_Slider.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,37 @@ double Slider::getInterval() const
181181
return range.interval;
182182
}
183183

184+
//==============================================================================
185+
186+
void Slider::setSkewFactor (double skewFactor)
187+
{
188+
if (skewFactor <= 0.0)
189+
{
190+
jassertfalse; // Skew factor must be positive
191+
return;
192+
}
193+
194+
if (! approximatelyEqual (range.skew, skewFactor))
195+
{
196+
range.skew = skewFactor;
197+
198+
// Reapply constraints to current values with new skew
199+
setDefaultValue (constrainValue (defaultValue));
200+
setValue (constrainValue (currentValue), dontSendNotification);
201+
setMinValue (constrainValue (minValue), dontSendNotification);
202+
setMaxValue (constrainValue (maxValue), dontSendNotification);
203+
204+
repaint();
205+
}
206+
}
207+
208+
double Slider::getSkewFactor() const
209+
{
210+
return range.skew;
211+
}
212+
213+
//==============================================================================
214+
184215
void Slider::setNumDecimalPlacesToDisplay (int decimalPlaces)
185216
{
186217
numDecimalPlaces = decimalPlaces;

modules/yup_gui/widgets/yup_Slider.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ class YUP_API Slider : public Component
163163
/** Returns the interval/step size for the slider. */
164164
double getInterval() const;
165165

166+
//==============================================================================
167+
/** Sets the skew factor for the slider's range.
168+
169+
The skew factor affects how values are distributed across the slider:
170+
- A value of 1.0 creates a linear distribution (no skewing)
171+
- Values < 1.0 allocate more space to the lower end of the range
172+
- Values > 1.0 allocate more space to the upper end of the range
173+
174+
This is particularly useful for parameters like frequency which benefit
175+
from logarithmic scaling.
176+
177+
@param skewFactor The skew factor to apply (must be > 0.0)
178+
*/
179+
void setSkewFactor (double skewFactor);
180+
181+
/** Returns the current skew factor for the slider's range. */
182+
double getSkewFactor() const;
183+
184+
//==============================================================================
166185
/** Sets the number of decimal places to use when displaying values.
167186
168187
@param decimalPlaces Number of decimal places (negative for automatic)

0 commit comments

Comments
 (0)