From 82073da570b26ea1efecd9a1a1e304693a19e25c Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 2 Oct 2017 09:23:17 +0100 Subject: [PATCH] Made the dsp::Filter copy constructor reset the state. Also added a couple of missing move constructors to that class --- modules/juce_dsp/processors/juce_IIRFilter.cpp | 13 +++++++++++++ modules/juce_dsp/processors/juce_IIRFilter.h | 13 +++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/juce_dsp/processors/juce_IIRFilter.cpp b/modules/juce_dsp/processors/juce_IIRFilter.cpp index 1c9229cbbb..96b4e2c229 100644 --- a/modules/juce_dsp/processors/juce_IIRFilter.cpp +++ b/modules/juce_dsp/processors/juce_IIRFilter.cpp @@ -45,6 +45,12 @@ IIR::Coefficients::Coefficients (const Coefficients& other) { } +template +IIR::Coefficients::Coefficients (Coefficients&& other) + : coefficients (static_cast&&> (other.coefficients)) +{ +} + template IIR::Coefficients& IIR::Coefficients::operator= (const Coefficients& other) { @@ -52,6 +58,13 @@ IIR::Coefficients& IIR::Coefficients::operator= (const return *this; } +template +IIR::Coefficients& IIR::Coefficients::operator= (Coefficients&& other) +{ + coefficients = static_cast&&> (other.coefficients); + return *this; +} + template IIR::Coefficients::Coefficients (NumericType b0, NumericType b1, NumericType a0, NumericType a1) diff --git a/modules/juce_dsp/processors/juce_IIRFilter.h b/modules/juce_dsp/processors/juce_IIRFilter.h index 056f8210cb..c910bd24dc 100644 --- a/modules/juce_dsp/processors/juce_IIRFilter.h +++ b/modules/juce_dsp/processors/juce_IIRFilter.h @@ -69,7 +69,10 @@ namespace IIR Filter (Coefficients* coefficientsToUse); /** Creates a copy of another filter. */ - Filter (const Filter&) = default; + Filter (const Filter& other) : coefficients (other.coefficients) { reset(); } + + /** Creates a copy of another filter. */ + Filter& operator= (const Filter& other) { coefficients = other.coefficients; reset(); } /** Move constructor. */ Filter (Filter&&) = default; @@ -89,10 +92,9 @@ namespace IIR Note that this clears the processing state, but the type of filter and its coefficients aren't changed. */ - void reset() { reset (SampleType {0}); } + void reset() { reset ({}); } /** Resets the filter's processing pipeline to a specific value. - @see reset */ void reset (SampleType resetToValue); @@ -156,11 +158,10 @@ namespace IIR Coefficients (NumericType b0, NumericType, NumericType b2, NumericType b3, NumericType a0, NumericType a1, NumericType a2, NumericType a3); - /** Creates a copy of another filter. */ Coefficients (const Coefficients&); - - /** Creates a copy of another filter. */ + Coefficients (Coefficients&&); Coefficients& operator= (const Coefficients&); + Coefficients& operator= (Coefficients&&); /** The Coefficients structure is ref-counted, so this is a handy type that can be used as a pointer to one.