Skip to content

Commit 3989abc

Browse files
committed
More tweaks
1 parent b6f6948 commit 3989abc

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

examples/graphics/source/examples/FilterDemo.h

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ class FrequencyResponsePlot : public yup::Component
727727
else
728728
label = yup::String (freq, 0);
729729

730-
g.fillFittedText (label, font, { x - 20, bounds.getBottom() - 15, 40, 15 }, yup::Justification::center);
730+
g.fillFittedText (label, font, { x - 20, bounds.getBottom() - 15, 40, 15 }, yup::Justification::center);
731731
}
732732

733733
// dB labels
@@ -772,6 +772,42 @@ class FrequencyResponsePlot : public yup::Component
772772

773773
//==============================================================================
774774

775+
class FilterOscilloscope : public yup::Component
776+
{
777+
public:
778+
void setRenderData (const std::vector<float>& data, int newReadPos)
779+
{
780+
renderData = data;
781+
}
782+
783+
void paint (yup::Graphics& g) override
784+
{
785+
auto bounds = getLocalBounds();
786+
787+
g.setFillColor (yup::Color (0xff101010));
788+
g.fillAll();
789+
790+
if (renderData.empty()) return;
791+
792+
yup::Path path;
793+
float xStep = static_cast<float> (bounds.getWidth()) / renderData.size();
794+
float centerY = bounds.getHeight() * 0.5f;
795+
796+
path.moveTo (0, centerY + renderData[0] * centerY);
797+
for (size_t i = 1; i < renderData.size(); ++i)
798+
path.lineTo (i * xStep, centerY + renderData[i] * centerY);
799+
800+
g.setStrokeColor (yup::Color (0xff4fc3f7));
801+
g.setStrokeWidth (2.0f);
802+
g.strokePath (path);
803+
}
804+
805+
private:
806+
std::vector<float> renderData;
807+
};
808+
809+
//==============================================================================
810+
775811
class FilterDemo
776812
: public yup::Component
777813
, public yup::AudioIODeviceCallback
@@ -1269,10 +1305,10 @@ class FilterDemo
12691305
std::vector<std::complex<double>> zeros;
12701306

12711307
// Extract poles and zeros based on filter type
1272-
if (auto biquad = std::dynamic_pointer_cast<yup::Biquad<float>> (currentFilter))
1308+
if (auto rbj = std::dynamic_pointer_cast<yup::RbjFilter<float>> (currentFilter))
12731309
{
12741310
// For biquad filters, calculate poles and zeros from coefficients
1275-
calculateBiquadPolesZeros (biquad, poles, zeros);
1311+
calculateBiquadPolesZeros (rbj->getCoefficients(), poles, zeros);
12761312
}
12771313
else if (auto butter = std::dynamic_pointer_cast<yup::ButterworthFilter<float>> (currentFilter))
12781314
{
@@ -1284,17 +1320,14 @@ class FilterDemo
12841320
polesZerosDisplay.updatePolesZeros (poles, zeros);
12851321
}
12861322

1287-
void calculateBiquadPolesZeros (std::shared_ptr<yup::Biquad<float>> biquad,
1323+
void calculateBiquadPolesZeros (yup::BiquadCoefficients<double> biquad,
12881324
std::vector<std::complex<double>>& poles,
12891325
std::vector<std::complex<double>>& zeros)
12901326
{
1291-
if (! biquad)
1292-
return;
1293-
12941327
// Get biquad coefficients (assuming they're accessible)
12951328
// This is a simplified version - you might need to access coefficients differently
1296-
double a1 = 0.0, a2 = 0.0; // Denominator coefficients
1297-
double b0 = 1.0, b1 = 0.0, b2 = 0.0; // Numerator coefficients
1329+
double a1 = biquad.a1, a2 = biquad.a2; // Denominator coefficients
1330+
double b0 = biquad.b0, b1 = biquad.b1, b2 = biquad.b2; // Numerator coefficients
12981331

12991332
// Calculate poles from denominator: 1 + a1*z^-1 + a2*z^-2 = 0
13001333
// Rearranged: z^2 + a1*z + a2 = 0
@@ -1473,41 +1506,7 @@ class FilterDemo
14731506
GroupDelayDisplay groupDelayDisplay;
14741507
StepResponseDisplay stepResponseDisplay;
14751508
PolesZerosDisplay polesZerosDisplay;
1476-
1477-
class Oscilloscope : public yup::Component
1478-
{
1479-
public:
1480-
void setRenderData (const std::vector<float>& data, int newReadPos)
1481-
{
1482-
renderData = data;
1483-
}
1484-
1485-
void paint (yup::Graphics& g) override
1486-
{
1487-
auto bounds = getLocalBounds();
1488-
1489-
g.setFillColor (yup::Color (0xff101010));
1490-
g.fillAll();
1491-
1492-
if (renderData.empty())
1493-
return;
1494-
1495-
yup::Path path;
1496-
float xStep = static_cast<float> (bounds.getWidth()) / renderData.size();
1497-
float centerY = bounds.getHeight() * 0.5f;
1498-
1499-
path.moveTo (0, centerY + renderData[0] * centerY);
1500-
for (size_t i = 1; i < renderData.size(); ++i)
1501-
path.lineTo (i * xStep, centerY + renderData[i] * centerY);
1502-
1503-
g.setStrokeColor (yup::Color (0xff4fc3f7));
1504-
g.setStrokeWidth (2.0f);
1505-
g.strokePath (path);
1506-
}
1507-
1508-
private:
1509-
std::vector<float> renderData;
1510-
} oscilloscope;
1509+
FilterOscilloscope oscilloscope;
15111510

15121511
// Audio buffer management
15131512
std::vector<float> inputData;

modules/yup_dsp/filters/yup_RbjFilter.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ namespace yup
4444
@see Biquad, FilterBase
4545
*/
4646
template <typename SampleType, typename CoeffType = double>
47-
class RbjFilter : public FilterBase<SampleType, CoeffType>
47+
class RbjFilter : public Biquad<SampleType, CoeffType>
4848
{
49+
using BaseFilterType = Biquad<SampleType, CoeffType>;
50+
4951
public:
5052
//==============================================================================
5153
/** Filter type enumeration specific to RBJ cookbook */
@@ -74,34 +76,33 @@ class RbjFilter : public FilterBase<SampleType, CoeffType>
7476
/** @internal */
7577
void reset() noexcept override
7678
{
77-
biquad.reset();
79+
BaseFilterType::reset();
7880
}
7981

8082
/** @internal */
8183
void prepare (double sampleRate, int maximumBlockSize) noexcept override
8284
{
83-
this->sampleRate = sampleRate;
84-
this->maximumBlockSize = maximumBlockSize;
85-
biquad.prepare (sampleRate, maximumBlockSize);
85+
BaseFilterType::prepare (sampleRate, maximumBlockSize);
86+
8687
updateCoefficients();
8788
}
8889

8990
/** @internal */
9091
SampleType processSample (SampleType inputSample) noexcept override
9192
{
92-
return biquad.processSample (inputSample);
93+
return BaseFilterType::processSample (inputSample);
9394
}
9495

9596
/** @internal */
9697
void processBlock (const SampleType* inputBuffer, SampleType* outputBuffer, int numSamples) noexcept override
9798
{
98-
biquad.processBlock (inputBuffer, outputBuffer, numSamples);
99+
BaseFilterType::processBlock (inputBuffer, outputBuffer, numSamples);
99100
}
100101

101102
/** @internal */
102103
DspMath::Complex<CoeffType> getComplexResponse (CoeffType frequency) const noexcept override
103104
{
104-
return biquad.getComplexResponse (frequency);
105+
return BaseFilterType::getComplexResponse (frequency);
105106
}
106107

107108
//==============================================================================
@@ -120,7 +121,9 @@ class RbjFilter : public FilterBase<SampleType, CoeffType>
120121
centerFreq = frequency;
121122
qFactor = q;
122123
gain = gainDb;
123-
this->sampleRate = sampleRate;
124+
125+
BaseFilterType::sampleRate = sampleRate;
126+
124127
updateCoefficients();
125128
}
126129

@@ -250,12 +253,10 @@ class RbjFilter : public FilterBase<SampleType, CoeffType>
250253
break;
251254
}
252255

253-
biquad.setCoefficients (coeffs);
256+
BaseFilterType::setCoefficients (coeffs);
254257
}
255258

256259
//==============================================================================
257-
Biquad<SampleType> biquad;
258-
259260
Type filterType = Type::peaking;
260261
CoeffType centerFreq = static_cast<CoeffType> (1000.0);
261262
CoeffType qFactor = static_cast<CoeffType> (0.707);

0 commit comments

Comments
 (0)