shithub: sox

ref: beb75f8713d9b867201c6525d41c767eb89ed049
dir: /src/breject.c/

View raw version
/*

    Band-reject effect file for SoX
    Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>

    This source code 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 source code 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 Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Code based on the band-reject implementation in

   Sound Processing Kit - A C++ Class Library for Audio Signal Processing
    Copyright (C) 1995-1998 Kai Lassfolk

    as described in

   Computer music: synthesis, composition, and performance
    Charles Dodge, Thomas A. Jerse
    [2nd ed.]
    Page 217

 */

#include <math.h>

#include "st.h"
#include "btrworth.h"



void
bandreject_getopts (effp, n, argv)
eff_t effp;
int n;
char **argv;
{
  butterworth_t butterworth = (butterworth_t)effp->priv;

  if (n != 2) {
    fail("Usage: bandreject FREQUENCY BANDWIDTH");
  }

  butterworth_start (effp);

  if (!(sscanf (argv [0], "%lf", &butterworth->frequency))) {
    fail("bandreject: illegal frequency");
  }

  if (!(sscanf (argv [1], "%lf", &butterworth->bandwidth))) {
   fail("bandreject: illegal bandwidth");
  }
}



void
bandreject_start (effp)
eff_t effp;
{
  butterworth_t butterworth = (butterworth_t) effp->priv;
  double c;
  double d;

  c = tan (M_PI * butterworth->bandwidth / effp->ininfo.rate);
  d = 2 * cos (2 * M_PI * butterworth->frequency / effp->ininfo.rate);

  butterworth->a [0] = 1.0 / (1.0 + c);
  butterworth->a [1] = -d * butterworth->a[0];
  butterworth->a [2] = butterworth->a[0];

  butterworth->b [0] = butterworth->a[1];
  butterworth->b [1] = (1.0 - c) * butterworth->a[0];
}