From 197446db5f9ea0ee7088fcb4b21b97d5f9865cc8 Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Mon, 7 Jul 2014 09:56:28 +0000 Subject: [PATCH] Add iir_coeff_copy() --- src/libiir/200_iir.c | 21 +++++++++++++++++++++ src/libiir/200_iir.h | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/libiir/200_iir.c b/src/libiir/200_iir.c index da59edf..4cb6b18 100644 --- a/src/libiir/200_iir.c +++ b/src/libiir/200_iir.c @@ -44,6 +44,27 @@ iir_coeff_new(int nc, const double* c, int nd, const double* d) +/* iir_coeff_copy() + * Deep copy of coefficient object. + */ +struct iir_coeff_t* +iir_coeff_copy(const struct iir_coeff_t* other) +{ + struct iir_coeff_t* coeff; + + coeff = malloc(sizeof(struct iir_coeff_t)); + coeff->nc = other->nc; + coeff->nd = other->nd; + coeff->c = malloc(sizeof(double) * coeff->nc); + coeff->d = malloc(sizeof(double) * coeff->nd); + memcpy(coeff->c, other->c, sizeof(double) * coeff->nc); + memcpy(coeff->d, other->d, sizeof(double) * coeff->nd); + + return coeff; +} + + + /* iir_coeff_free() * Frees memory associated with ‘coeff’. */ diff --git a/src/libiir/200_iir.h b/src/libiir/200_iir.h index ed6d000..0d1d713 100644 --- a/src/libiir/200_iir.h +++ b/src/libiir/200_iir.h @@ -55,6 +55,18 @@ struct iir_coeff_t* iir_coeff_new(int nc, const double* c, int nd, +/*! \brief Create copy of general IIR filter + +\param other Set of IIR filter coefficients to copy. +\returns Pointer to new general IIR filter object. + +Performs a deep copy of the set of IIR coefficients contained within \a other. + +*/ +struct iir_coeff_t* iir_coeff_copy(const struct iir_coeff_t* other); + + + /*! \brief Free general IIR filter \param coeff Pointer to IIR filter object. May be 0.