~ubuntu-branches/ubuntu/feisty/muse/feisty

« back to all changes in this revision

Viewing changes to synti/stklib/PoleZero.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************/
 
2
/*  PoleZero (1-pole, 1-zero) Filter Class */
 
3
/*  by Gary P. Scavone, 1999               */
 
4
/*                                         */
 
5
/*  See books on filters to understand     */
 
6
/*  more about how this works.  Nothing    */
 
7
/*  out of the ordinary in this version.   */
 
8
/*******************************************/
 
9
 
 
10
#include "PoleZero.h"
 
11
 
 
12
PoleZero :: PoleZero() : Filter()
 
13
{
 
14
  inputs = (MY_FLOAT *) malloc(sizeof(MY_FLOAT));
 
15
  outputs = (MY_FLOAT *) malloc(sizeof(MY_FLOAT));
 
16
  b0Coeff = (MY_FLOAT) 1.0;
 
17
  b1Coeff = (MY_FLOAT) 0.0;
 
18
  a1Coeff = (MY_FLOAT) 0.0;
 
19
  gain = (MY_FLOAT) 1.0;
 
20
  this->clear();
 
21
}
 
22
 
 
23
PoleZero :: ~PoleZero()
 
24
{
 
25
  free(inputs);
 
26
  free(outputs);
 
27
}
 
28
 
 
29
void PoleZero :: clear()
 
30
{
 
31
  inputs[0] = (MY_FLOAT) 0.0;
 
32
  outputs[0] = (MY_FLOAT) 0.0;
 
33
  lastOutput = (MY_FLOAT) 0.0;
 
34
}
 
35
 
 
36
void PoleZero :: setA1(MY_FLOAT coeff)
 
37
{
 
38
  a1Coeff = coeff;
 
39
}
 
40
 
 
41
void PoleZero :: setB0(MY_FLOAT coeff)
 
42
{
 
43
  b0Coeff = coeff;
 
44
}
 
45
 
 
46
void PoleZero :: setB1(MY_FLOAT coeff)
 
47
{
 
48
  b1Coeff = coeff;
 
49
}
 
50
 
 
51
void PoleZero :: setGain(MY_FLOAT aValue)
 
52
{
 
53
  gain = aValue;
 
54
}
 
55
 
 
56
// PoleZero is one pole, one zero filter
 
57
// Look it up in your favorite DSP text
 
58
MY_FLOAT PoleZero :: tick(MY_FLOAT sample)
 
59
{
 
60
  MY_FLOAT in_sample = gain*sample;
 
61
 
 
62
  lastOutput = b0Coeff*in_sample + b1Coeff*inputs[0] - a1Coeff*outputs[0];
 
63
  inputs[0] = in_sample;
 
64
  outputs[0] = lastOutput;
 
65
 
 
66
  return lastOutput;
 
67
}
 
68