From b12a49542a1985d6b1638eb56609fa033eda0a30 Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Mon, 7 Jul 2014 11:57:16 +0000 Subject: [PATCH] Add interface to query coefficients from chain --- src/libiir/200_filter.c | 19 +++++++++++++++++++ src/libiir/200_filter.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/libiir/200_filter.c b/src/libiir/200_filter.c index d69b62b..3fb7f2d 100644 --- a/src/libiir/200_filter.c +++ b/src/libiir/200_filter.c @@ -217,6 +217,25 @@ iir_filter(struct iir_filter_t* fi, double samp) +int +iir_filter_coeff_sets(const struct iir_filter_t* fi) +{ + int count; + for(count = 0; fi; ++count) fi = fi->next; + return count; +} + + + +struct iir_coeff_t* +iir_filter_coeff_set(const struct iir_filter_t* fi, int idx) +{ + while(idx--) fi = fi->next; + return iir_coeff_new(fi->nc, fi->c, fi->nd, fi->d); +} + + + /* options for text editors vim: expandtab:ts=4:sw=4 */ diff --git a/src/libiir/200_filter.h b/src/libiir/200_filter.h index 247a8ba..0ea2ea5 100644 --- a/src/libiir/200_filter.h +++ b/src/libiir/200_filter.h @@ -121,6 +121,35 @@ double iir_filter(struct iir_filter_t* fi, double samp); +/*! \brief Count number of coefficient sets in IIR filter chain + +\param fi Filter object. +\returns Number of coefficient sets in chain (≥1). + +Returns the number of discrete IIR filter coefficient sets used in the filter +object \a fi. There will always be at least one set. + +*/ +int iir_filter_coeff_sets(const struct iir_filter_t* fi); + + + +/*! \brief Get IIR coefficient set from filter chain + +\param fi Filter object. +\param idx Index of coefficient set (0 ≤ \a idx < \ref iir_filter_coeff_sets()). +\returns Newly-allocated coefficient set object. + +Extracts the IIR filter coefficient set for the given step (\a idx) in the chain +of filters in \a fi. Returns a newly-allocated filter coefficient set object +which can be freed with \ref iir_coeff_free(). + +*/ +struct iir_coeff_t* iir_filter_coeff_set(const struct iir_filter_t* fi, + int idx); + + + /*!@}*/ /* options for text editors vim: expandtab:ts=4:sw=4:syntax=c.doxygen