~mixxxdevelopers/mixxx/features_library_scanner

« back to all changes in this revision

Viewing changes to mixxx/mixxx/engineIIRfilter.cpp

  • Committer: tuehaste
  • Date: 2002-02-26 11:12:07 UTC
  • Revision ID: vcs-imports@canonical.com-20020226111207-5rly26cj9gdd19ba
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "engineIIRfilter.h"
 
2
 
 
3
EngineIIRfilter::EngineIIRfilter(int potmeter_midi, int button_midi,
 
4
                                 int button_bit, MidiObject *midi, const double *_coefs) {
 
5
  //  Initialize the buttons:
 
6
  killbutton = new ControlPushButton("kill", simulated_latching, button_midi,
 
7
                                     button_bit, midi);
 
8
  connect(killbutton, SIGNAL(valueChanged(valueType)), this, SLOT(slotUpdate()));
 
9
 
 
10
  filterpot = new ControlPotmeter("filterpot", potmeter_midi, midi, 0., 2.);
 
11
  connect(filterpot, SIGNAL(valueChanged(FLOAT)), this, SLOT(slotUpdate()));
 
12
 
 
13
  coefs = _coefs;
 
14
}
 
15
 
 
16
EngineIIRfilter::~EngineIIRfilter() {
 
17
  delete killbutton;
 
18
  delete filterpot;
 
19
}
 
20
 
 
21
void EngineIIRfilter::process(CSAMPLE *source, CSAMPLE *destination, int buf_size) {
 
22
  double GAIN =  coefs[0];
 
23
  for (int i=0; i<buf_size; i++) {
 
24
    xv[0] = xv[1]; xv[1] = xv[2]; xv[2] = xv[3]; xv[3] = xv[4];
 
25
    xv[4] = xv[5]; xv[5] = xv[6]; xv[6] = xv[7]; xv[7] = xv[8]; 
 
26
    xv[8] = source[i] / GAIN;
 
27
    yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; yv[3] = yv[4];
 
28
    yv[4] = yv[5]; yv[5] = yv[6]; yv[6] = yv[7]; yv[7] = yv[8]; 
 
29
 
 
30
    yv[8] =   (xv[0] + xv[8]) + coefs[1] * (xv[1] + xv[7]) + 
 
31
        coefs[2] * (xv[2] + xv[6])
 
32
        + coefs[3] * (xv[3] + xv[5]) + coefs[4] * xv[4]
 
33
        + (coefs[5] * yv[0]) + ( coefs[6] * yv[1])
 
34
        + (coefs[7] * yv[2]) + ( coefs[8] * yv[3])
 
35
        + (coefs[9] * yv[4]) + ( coefs[10] * yv[5])
 
36
        + (coefs[11] * yv[6]) + ( coefs[12] * yv[7]);
 
37
    
 
38
    destination[i] += (gain-1)*yv[8];
 
39
  }
 
40
}
 
41
 
 
42
void EngineIIRfilter::slotUpdate() {
 
43
  // We've been called when either the killbutton or the potmeter has
 
44
  // been touched. We have to check both.
 
45
  if (killbutton->getValue()==down)
 
46
    gain = 0;
 
47
  else
 
48
    gain = filterpot->getValue();
 
49
}