shithub: aubio

ref: 992beaa9bea5d3cd1aae961f80f581d2003bcc79
dir: /src/temporal/biquad.c/

View raw version
/*
   Copyright (C) 2003 Paul Brossier

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include "aubio_priv.h"
#include "fvec.h"
#include "lvec.h"
#include "temporal/filter.h"

uint_t
aubio_filter_set_biquad (aubio_filter_t * f, lsmp_t b0, lsmp_t b1, lsmp_t b2,
    lsmp_t a1, lsmp_t a2) {
  uint_t order = aubio_filter_get_order (f);
  lvec_t *bs = aubio_filter_get_feedforward (f);
  lvec_t *as = aubio_filter_get_feedback (f);

  if (order != 3) {
    AUBIO_ERROR ("order of biquad filter must be 3, not %d\n", order);
    return AUBIO_FAIL;
  }
  bs->data[0][0] = b0;
  bs->data[0][1] = b1;
  bs->data[0][2] = b2;
  as->data[0][0] = 1.;
  as->data[0][1] = a1;
  as->data[0][1] = a2;
  return AUBIO_OK;
}

aubio_filter_t *
new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2,
    uint_t channels)
{
  aubio_filter_t *f = new_aubio_filter (3, channels);
  aubio_filter_set_biquad (f, b0, b1, b2, a1, a2);
  return f;
}