Add iir_coeff_copy()

This commit is contained in:
Laurence Withers 2014-07-07 09:56:28 +00:00
parent a57e239d10
commit 197446db5f
2 changed files with 33 additions and 0 deletions

View File

@ -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.
*/

View File

@ -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.