summaryrefslogtreecommitdiff
path: root/os2eindopdracht/FilterWorker.cpp
blob: 495d3d1afd3371ca88dbfddfe246eb88a6a26943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "FilterWorker.h"
#include "SampleBlock.h"

FilterWorker::FilterWorker(SampleBlock& input, SampleBlock& output) {
	_input = &input;
	_output = &output;
}

void FilterWorker::filter(Coefficients bass, Coefficients treble) {
  for (size_t i = 0; i < _output->size; i++) {
    double x_pp = i < 2 ? 0 : *(_input->begin + i - 2);
    double x_p = i < 1 ? 0 : *(_input->begin + i - 1);
    double x_ = i < 0 ? 0 : *(_input->begin + i - 0);
    double y_pp = i < 2 ? 0 : *(_output->begin + i - 2);
    double y_p = i < 1 ? 0 : *(_output->begin + i - 1);
    *(_output->begin + i) = bass.b0 * x_ +
		                        bass.b1 * x_p +
		                        bass.b2 * x_pp +
		                        bass.a1 * y_p +
		                        bass.a2 * y_pp;
  }
  for (size_t i = 0; i < _output->size; i++) {
    double x_pp = i < 2 ? 0 : *(_input->begin + i - 2);
    double x_p = i < 1 ? 0 : *(_input->begin + i - 1);
    double x_ = i < 0 ? 0 : *(_input->begin + i - 0);
    double y_pp = i < 2 ? 0 : *(_output->begin + i - 2);
    double y_p = i < 1 ? 0 : *(_output->begin + i - 1);
    *(_output->begin + i) = treble.b0 * x_ +
		                        treble.b1 * x_p +
		                        treble.b2 * x_pp +
		                        treble.a1 * y_p +
		                        treble.a2 * y_pp;
  }
}