1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

DSP: Fixed an issue returning arrays of reference counted objects

This commit is contained in:
Tom Poole 2018-09-10 16:02:26 +01:00
parent 856d7dc333
commit 1396d7cfc5
3 changed files with 52 additions and 52 deletions

View file

@ -337,7 +337,7 @@ Array<double> FilterDesign<FloatType>::getPartialImpulseResponseHn (int n, doubl
}
template <typename FloatType>
Array<IIR::Coefficients<FloatType>>
ReferenceCountedArray<IIR::Coefficients<FloatType>>
FilterDesign<FloatType>::designIIRLowpassHighOrderButterworthMethod (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
@ -348,7 +348,7 @@ Array<IIR::Coefficients<FloatType>>
}
template <typename FloatType>
Array<IIR::Coefficients<FloatType>>
ReferenceCountedArray<IIR::Coefficients<FloatType>>
FilterDesign<FloatType>::designIIRLowpassHighOrderChebyshev1Method (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
@ -359,7 +359,7 @@ Array<IIR::Coefficients<FloatType>>
}
template <typename FloatType>
Array<IIR::Coefficients<FloatType>>
ReferenceCountedArray<IIR::Coefficients<FloatType>>
FilterDesign<FloatType>::designIIRLowpassHighOrderChebyshev2Method (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
@ -370,7 +370,7 @@ Array<IIR::Coefficients<FloatType>>
}
template <typename FloatType>
Array<IIR::Coefficients<FloatType>>
ReferenceCountedArray<IIR::Coefficients<FloatType>>
FilterDesign<FloatType>::designIIRLowpassHighOrderEllipticMethod (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
@ -381,7 +381,7 @@ Array<IIR::Coefficients<FloatType>>
}
template <typename FloatType>
Array<IIR::Coefficients<FloatType>>
ReferenceCountedArray<IIR::Coefficients<FloatType>>
FilterDesign<FloatType>::designIIRLowpassHighOrderGeneralMethod (int type, FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
@ -510,7 +510,7 @@ Array<IIR::Coefficients<FloatType>>
g.add ((1.0 - p[i + r]) / (1.0 - z[i]));
}
Array<IIR::Coefficients<FloatType>> cascadedCoefficients;
ReferenceCountedArray<IIR::Coefficients<FloatType>> cascadedCoefficients;
if (r == 1)
{
@ -518,7 +518,7 @@ Array<IIR::Coefficients<FloatType>>
auto b1 = b0;
auto a1 = static_cast<FloatType> (-std::real (p[0]));
cascadedCoefficients.add ({ b0, b1, 1.0f, a1 });
cascadedCoefficients.add (new IIR::Coefficients<FloatType> (b0, b1, 1.0f, a1));
}
for (int i = 0; i < L; ++i)
@ -532,14 +532,14 @@ Array<IIR::Coefficients<FloatType>>
auto a1 = static_cast<FloatType> (std::real (-p[i+r] - std::conj (p[i + r])));
auto a2 = static_cast<FloatType> (std::real ( p[i+r] * std::conj (p[i + r])));
cascadedCoefficients.add ({ b0, b1, b2, 1, a1, a2 });
cascadedCoefficients.add (new IIR::Coefficients<FloatType> (b0, b1, b2, 1, a1, a2));
}
return cascadedCoefficients;
}
template <typename FloatType>
Array<IIR::Coefficients<FloatType>>
ReferenceCountedArray<IIR::Coefficients<FloatType>>
FilterDesign<FloatType>::designIIRLowpassHighOrderButterworthMethod (FloatType frequency,
double sampleRate, int order)
{
@ -547,7 +547,7 @@ Array<IIR::Coefficients<FloatType>>
jassert (frequency > 0 && frequency <= sampleRate * 0.5);
jassert (order > 0);
Array<IIR::Coefficients<FloatType>> arrayFilters;
ReferenceCountedArray<IIR::Coefficients<FloatType>> arrayFilters;
if (order % 2 == 1)
{
@ -574,7 +574,7 @@ Array<IIR::Coefficients<FloatType>>
}
template <typename FloatType>
Array<IIR::Coefficients<FloatType>>
ReferenceCountedArray<IIR::Coefficients<FloatType>>
FilterDesign<FloatType>::designIIRHighpassHighOrderButterworthMethod (FloatType frequency,
double sampleRate, int order)
{
@ -582,7 +582,7 @@ Array<IIR::Coefficients<FloatType>>
jassert (frequency > 0 && frequency <= sampleRate * 0.5);
jassert (order > 0);
Array<IIR::Coefficients<FloatType>> arrayFilters;
ReferenceCountedArray<IIR::Coefficients<FloatType>> arrayFilters;
if (order % 2 == 1)
{
@ -678,14 +678,14 @@ typename FilterDesign<FloatType>::IIRPolyphaseAllpassStructure
IIRPolyphaseAllpassStructure structure;
for (int i = 0; i < N; i += 2)
structure.directPath.add (IIR::Coefficients<FloatType> (static_cast<FloatType> (ai[i]),
0, 1, 1, 0, static_cast<FloatType> (ai[i])));
structure.directPath.add (new IIR::Coefficients<FloatType> (static_cast<FloatType> (ai[i]),
0, 1, 1, 0, static_cast<FloatType> (ai[i])));
structure.delayedPath.add (IIR::Coefficients<FloatType> (0, 1, 1, 0));
structure.delayedPath.add (new IIR::Coefficients<FloatType> (0, 1, 1, 0));
for (int i = 1; i < N; i += 2)
structure.delayedPath.add (IIR::Coefficients<FloatType> (static_cast<FloatType> (ai[i]),
0, 1, 1, 0, static_cast<FloatType> (ai[i])));
structure.delayedPath.add (new IIR::Coefficients<FloatType> (static_cast<FloatType> (ai[i]),
0, 1, 1, 0, static_cast<FloatType> (ai[i])));
return structure;
}

View file

@ -158,10 +158,10 @@ struct FilterDesign
@param stopbandAttenuationdB the attenuation in dB expected in the stop band
*/
static Array<IIRCoefficients> designIIRLowpassHighOrderButterworthMethod (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
static ReferenceCountedArray<IIRCoefficients> designIIRLowpassHighOrderButterworthMethod (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
//==============================================================================
/** This method returns an array of IIR::Coefficients, made to be used in
@ -174,8 +174,8 @@ struct FilterDesign
an attenuation of -6 dB times order / octave
*/
static Array<IIRCoefficients> designIIRLowpassHighOrderButterworthMethod (FloatType frequency, double sampleRate,
int order);
static ReferenceCountedArray<IIRCoefficients> designIIRLowpassHighOrderButterworthMethod (FloatType frequency, double sampleRate,
int order);
/** This method returns an array of IIR::Coefficients, made to be used in
cascaded IIRFilters, providing a minimum phase high-pass filter without any
@ -187,8 +187,8 @@ struct FilterDesign
an attenuation of -6 dB times order / octave
*/
static Array<IIRCoefficients> designIIRHighpassHighOrderButterworthMethod (FloatType frequency, double sampleRate,
int order);
static ReferenceCountedArray<IIRCoefficients> designIIRHighpassHighOrderButterworthMethod (FloatType frequency, double sampleRate,
int order);
/** This method returns an array of IIR::Coefficients, made to be used in
cascaded IIRFilters, providing a minimum phase low-pass filter without any
@ -204,10 +204,10 @@ struct FilterDesign
@param passbandAttenuationdB the lowest attenuation in dB expected in the pass band
@param stopbandAttenuationdB the attenuation in dB expected in the stop band
*/
static Array<IIRCoefficients> designIIRLowpassHighOrderChebyshev1Method (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
static ReferenceCountedArray<IIRCoefficients> designIIRLowpassHighOrderChebyshev1Method (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
/** This method returns an array of IIR::Coefficients, made to be used in
cascaded IIRFilters, providing a minimum phase low-pass filter without any
@ -223,10 +223,10 @@ struct FilterDesign
@param passbandAttenuationdB the lowest attenuation in dB expected in the pass band
@param stopbandAttenuationdB the attenuation in dB expected in the stop band
*/
static Array<IIRCoefficients> designIIRLowpassHighOrderChebyshev2Method (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
static ReferenceCountedArray<IIRCoefficients> designIIRLowpassHighOrderChebyshev2Method (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
/** This method returns an array of IIR::Coefficients, made to be used in
cascaded IIR::Filters, providing a minimum phase low-pass filter with ripples
@ -242,10 +242,10 @@ struct FilterDesign
@param passbandAttenuationdB the lowest attenuation in dB expected in the pass band
@param stopbandAttenuationdB the attenuation in dB expected in the stop band
*/
static Array<IIRCoefficients> designIIRLowpassHighOrderEllipticMethod (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
static ReferenceCountedArray<IIRCoefficients> designIIRLowpassHighOrderEllipticMethod (FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
/** The structure returned by the function designIIRLowpassHalfBandPolyphaseAllpassMethod.
@ -255,7 +255,7 @@ struct FilterDesign
parallel paths, which must be summed at the end to get the high order efficient
low-pass filtering.
*/
struct IIRPolyphaseAllpassStructure { Array<IIRCoefficients> directPath, delayedPath; };
struct IIRPolyphaseAllpassStructure { ReferenceCountedArray<IIRCoefficients> directPath, delayedPath; };
/** This method generates arrays of IIR::Coefficients for a low-pass filter, with
a cutoff frequency at half band, using an algorithm described in the article
@ -284,10 +284,10 @@ private:
//==============================================================================
static Array<double> getPartialImpulseResponseHn (int n, double kp);
static Array<IIRCoefficients> designIIRLowpassHighOrderGeneralMethod (int type, FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
static ReferenceCountedArray<IIRCoefficients> designIIRLowpassHighOrderGeneralMethod (int type, FloatType frequency, double sampleRate,
FloatType normalizedTransitionWidth,
FloatType passbandAttenuationdB,
FloatType stopbandAttenuationdB);
FilterDesign() = delete;
};

View file

@ -290,17 +290,17 @@ public:
dsp::IIR::Coefficients<SampleType> coeffsDown = getCoefficients (structureDown);
latency += static_cast<SampleType> (-(coeffsDown.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * MathConstants<double>::twoPi));
for (auto& i : structureUp.directPath)
coefficientsUp.add (i.coefficients[0]);
for (auto i = 0; i < structureUp.directPath.size(); ++i)
coefficientsUp.add (structureUp.delayedPath.getObjectPointer (i)->coefficients[0]);
for (auto i = 1; i < structureUp.delayedPath.size(); ++i)
coefficientsUp.add (structureUp.delayedPath[i].coefficients[0]);
coefficientsUp.add (structureUp.delayedPath.getObjectPointer (i)->coefficients[0]);
for (auto& i : structureDown.directPath)
coefficientsDown.add (i.coefficients[0]);
for (auto i = 0; i < structureDown.directPath.size(); ++i)
coefficientsDown.add (structureUp.delayedPath.getObjectPointer (i)->coefficients[0]);
for (auto i = 1; i < structureDown.delayedPath.size(); ++i)
coefficientsDown.add (structureDown.delayedPath[i].coefficients[0]);
coefficientsDown.add (structureUp.delayedPath.getObjectPointer (i)->coefficients[0]);
v1Up.setSize (static_cast<int> (this->numChannels), coefficientsUp.size());
v1Down.setSize (static_cast<int> (this->numChannels), coefficientsDown.size());
@ -478,9 +478,9 @@ private:
for (auto n = 0; n < structure.directPath.size(); ++n)
{
auto* coeffs = structure.directPath.getReference (n).getRawCoefficients();
auto* coeffs = structure.directPath.getObjectPointer (n)->getRawCoefficients();
if (structure.directPath[n].getFilterOrder() == 1)
if (structure.directPath.getObjectPointer (n)->getFilterOrder() == 1)
{
numerator1 = numerator1.getProductWith (dsp::Polynomial<SampleType> ({ coeffs[0], coeffs[1] }));
denominator1 = denominator1.getProductWith (dsp::Polynomial<SampleType> ({ one, coeffs[2] }));
@ -494,9 +494,9 @@ private:
for (auto n = 0; n < structure.delayedPath.size(); ++n)
{
auto* coeffs = structure.delayedPath.getReference (n).getRawCoefficients();
auto* coeffs = structure.delayedPath.getObjectPointer (n)->getRawCoefficients();
if (structure.delayedPath[n].getFilterOrder() == 1)
if (structure.delayedPath.getObjectPointer (n)->getFilterOrder() == 1)
{
numerator2 = numerator2.getProductWith (dsp::Polynomial<SampleType> ({ coeffs[0], coeffs[1] }));
denominator2 = denominator2.getProductWith (dsp::Polynomial<SampleType> ({ one, coeffs[2] }));