@@ -630,19 +630,21 @@ int FilterDesigner<CoeffType>::designLinkwitzRiley (
630630// ==============================================================================
631631
632632template <typename CoeffType>
633- std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRLowpass (
633+ void FilterDesigner<CoeffType>::designFIRLowpass (
634+ std::vector<CoeffType>& coefficients,
634635 int numCoefficients,
635636 CoeffType cutoffFreq,
636637 double sampleRate,
637- WindowType windowType) noexcept
638+ WindowType windowType,
639+ CoeffType windowParameter) noexcept
638640{
639641 jassert (numCoefficients > 0 );
640642 jassert (cutoffFreq > static_cast <CoeffType> (0.0 ));
641643 jassert (sampleRate > 0.0 );
642644 jassert (cutoffFreq < static_cast <CoeffType> (sampleRate / 2.0 ));
643645
644646 numCoefficients = nextOdd (numCoefficients);
645- std::vector<CoeffType> coefficients (numCoefficients);
647+ coefficients. resize (numCoefficients);
646648
647649 const auto normalizedCutoff = static_cast <CoeffType> (2.0 ) * cutoffFreq / static_cast <CoeffType> (sampleRate);
648650 const int center = (numCoefficients - 1 ) / 2 ;
@@ -664,25 +666,27 @@ std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRLowpass (
664666 // Apply window function
665667 for (int i = 0 ; i < numCoefficients; ++i)
666668 {
667- const auto windowValue = WindowFunctions<CoeffType>::getValue (windowType, i, numCoefficients);
669+ const auto windowValue = WindowFunctions<CoeffType>::getValue (windowType, i, numCoefficients, windowParameter );
668670 coefficients[i] *= windowValue;
669671 }
670672
671673 // Normalization
672674 const auto sum = std::accumulate (coefficients.begin (), coefficients.end (), static_cast <CoeffType> (0.0 ));
673675 if (sum != static_cast <CoeffType> (0.0 ))
676+ {
674677 for (auto & c : coefficients)
675678 c /= sum;
676-
677- return coefficients;
679+ }
678680}
679681
680682template <typename CoeffType>
681- std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRHighpass (
683+ void FilterDesigner<CoeffType>::designFIRHighpass (
684+ std::vector<CoeffType>& coefficients,
682685 int numCoefficients,
683686 CoeffType cutoffFreq,
684687 double sampleRate,
685- WindowType windowType) noexcept
688+ WindowType windowType,
689+ CoeffType windowParameter) noexcept
686690{
687691 jassert (numCoefficients > 0 );
688692 jassert (cutoffFreq > static_cast <CoeffType> (0.0 ));
@@ -691,7 +695,7 @@ std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRHighpass (
691695
692696 // Generate lowpass first
693697 numCoefficients = nextOdd (numCoefficients);
694- auto coefficients = designFIRLowpass (numCoefficients, cutoffFreq, sampleRate, windowType);
698+ designFIRLowpass (coefficients, numCoefficients, cutoffFreq, sampleRate, windowType);
695699
696700 // Convert to highpass using spectral inversion
697701 const int center = (numCoefficients - 1 ) / 2 ;
@@ -707,19 +711,21 @@ std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRHighpass (
707711 hpi += coefficients[n] * ((n & 1 ) ? static_cast <CoeffType> (-1.0 ) : static_cast <CoeffType> (1.0 ));
708712
709713 if (hpi != static_cast <CoeffType> (0.0 ))
714+ {
710715 for (auto & c : coefficients)
711716 c /= hpi;
712-
713- return coefficients;
717+ }
714718}
715719
716720template <typename CoeffType>
717- std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRBandpass (
721+ void FilterDesigner<CoeffType>::designFIRBandpass (
722+ std::vector<CoeffType>& coefficients,
718723 int numCoefficients,
719724 CoeffType lowCutoffFreq,
720725 CoeffType highCutoffFreq,
721726 double sampleRate,
722- WindowType windowType) noexcept
727+ WindowType windowType,
728+ CoeffType windowParameter) noexcept
723729{
724730 jassert (numCoefficients > 0 );
725731 jassert (lowCutoffFreq > static_cast <CoeffType> (0.0 ));
@@ -728,7 +734,7 @@ std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRBandpass (
728734 jassert (highCutoffFreq < static_cast <CoeffType> (sampleRate / 2.0 ));
729735
730736 numCoefficients = nextOdd (numCoefficients);
731- std::vector<CoeffType> coefficients (numCoefficients);
737+ coefficients. resize (numCoefficients);
732738
733739 const auto normalizedLow = static_cast <CoeffType> (2.0 ) * lowCutoffFreq / static_cast <CoeffType> (sampleRate);
734740 const auto normalizedHigh = static_cast <CoeffType> (2.0 ) * highCutoffFreq / static_cast <CoeffType> (sampleRate);
@@ -754,20 +760,20 @@ std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRBandpass (
754760 // Apply window function
755761 for (int i = 0 ; i < numCoefficients; ++i)
756762 {
757- const auto windowValue = WindowFunctions<CoeffType>::getValue (windowType, i, numCoefficients);
763+ const auto windowValue = WindowFunctions<CoeffType>::getValue (windowType, i, numCoefficients, windowParameter );
758764 coefficients[i] *= windowValue;
759765 }
760-
761- return coefficients;
762766}
763767
764768template <typename CoeffType>
765- std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRBandstop (
769+ void FilterDesigner<CoeffType>::designFIRBandstop (
770+ std::vector<CoeffType>& coefficients,
766771 int numCoefficients,
767772 CoeffType lowCutoffFreq,
768773 CoeffType highCutoffFreq,
769774 double sampleRate,
770- WindowType windowType) noexcept
775+ WindowType windowType,
776+ CoeffType windowParameter) noexcept
771777{
772778 jassert (numCoefficients > 0 );
773779 jassert (lowCutoffFreq > static_cast <CoeffType> (0.0 ));
@@ -777,7 +783,7 @@ std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRBandstop (
777783
778784 // Generate bandpass first
779785 numCoefficients = nextOdd (numCoefficients);
780- auto coefficients = designFIRBandpass (numCoefficients, lowCutoffFreq, highCutoffFreq, sampleRate, windowType);
786+ designFIRBandpass (coefficients, numCoefficients, lowCutoffFreq, highCutoffFreq, sampleRate, windowType);
781787
782788 // Convert to bandstop using spectral inversion
783789 const int center = (numCoefficients - 1 ) / 2 ;
@@ -787,8 +793,6 @@ std::vector<CoeffType> FilterDesigner<CoeffType>::designFIRBandstop (
787793
788794 // Add unit impulse at center
789795 coefficients[center] += static_cast <CoeffType> (1.0 );
790-
791- return coefficients;
792796}
793797
794798// ==============================================================================
0 commit comments