Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 77 lines (69 sloc) 2.296 kB
3a01ece @mhroth First commit of DspHighpassFilter
authored
1 /*
b3b7ef0 @mhroth Update lop~, hip~, and bp~ to take pre-resolved buffers.
authored
2 * Copyright 2009,2010,2011,2012 Reality Jockey, Ltd.
3a01ece @mhroth First commit of DspHighpassFilter
authored
3 * info@rjdj.me
4 * http://rjdj.me/
5 *
6 * This file is part of ZenGarden.
7 *
8 * ZenGarden is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ZenGarden is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
abb33ec First commit of current source.
Martin Roth authored
23 #include "DspLowpassFilter.h"
c5f37a0 @mhroth Add DspLowpassFilter (lop~)
authored
24 #include "PdGraph.h"
abb33ec First commit of current source.
Martin Roth authored
25
7329847 @mhroth Add static factory method to all objects in order to create an object…
authored
26 MessageObject *DspLowpassFilter::newObject(PdMessage *initMessage, PdGraph *graph) {
27 return new DspLowpassFilter(initMessage, graph);
28 }
29
b3b7ef0 @mhroth Update lop~, hip~, and bp~ to take pre-resolved buffers.
authored
30 DspLowpassFilter::DspLowpassFilter(PdMessage *initMessage, PdGraph *graph) : DspFilter(2, graph) {
31 calcFiltCoeff(initMessage->isFloat(0) ? initMessage->getFloat(0) : graph->getSampleRate()/2.0f);
abb33ec First commit of current source.
Martin Roth authored
32 }
33
34 DspLowpassFilter::~DspLowpassFilter() {
0210299 Reduce memory usage of lop~ and hip~ by allocating coefficient buffer…
Martin Roth authored
35 // nothing to do
abb33ec First commit of current source.
Martin Roth authored
36 }
37
b3b7ef0 @mhroth Update lop~, hip~, and bp~ to take pre-resolved buffers.
authored
38 // http://en.wikipedia.org/wiki/Low_pass_filter
39 void DspLowpassFilter::calcFiltCoeff(float fc) {
40 if (fc > 0.5f * graph->getSampleRate()) fc = 0.5f * graph->getSampleRate();
41 else if (fc < 0.0f) fc = 0.0f;
42
43 float wc = 2.0f*M_PI*fc;
44 float alpha = wc / (wc + graph->getSampleRate());
45 b[0] = alpha;
46 b[1] = 0.0f;
47 b[2] = 0.0f;
48 b[3] = -(1.0f-alpha);
49 b[4] = 0.0f;
abb33ec First commit of current source.
Martin Roth authored
50 }
51
c5f37a0 @mhroth Add DspLowpassFilter (lop~)
authored
52 void DspLowpassFilter::processMessage(int inletIndex, PdMessage *message) {
abb33ec First commit of current source.
Martin Roth authored
53 switch (inletIndex) {
54 case 0: {
257b8bf @mhroth Update lop~ to also accept float message inputs on the left inlet, sp…
authored
55 switch (message->getType(0)) {
56 case FLOAT: {
b3b7ef0 @mhroth Update lop~, hip~, and bp~ to take pre-resolved buffers.
authored
57 // signalConstant = message->getFloat(0);
257b8bf @mhroth Update lop~ to also accept float message inputs on the left inlet, sp…
authored
58 break;
59 }
60 case SYMBOL: {
61 if (message->isSymbol(0, "clear")) {
b848dc2 @mhroth A presumably working buffer reuse.
authored
62 x1 = x2 = dspBufferAtOutlet[0][0] = dspBufferAtOutlet[0][1] = 0.0f;
257b8bf @mhroth Update lop~ to also accept float message inputs on the left inlet, sp…
authored
63 }
64 break;
65 }
b3b7ef0 @mhroth Update lop~, hip~, and bp~ to take pre-resolved buffers.
authored
66 default: break;
abb33ec First commit of current source.
Martin Roth authored
67 }
68 break;
69 }
70 case 1: {
488fe6b @mhroth Update lop~, hip~, and bp~ to new dsp architecture.
authored
71 if (message->isFloat(0)) calcFiltCoeff(message->getFloat(0));
abb33ec First commit of current source.
Martin Roth authored
72 break;
73 }
b3b7ef0 @mhroth Update lop~, hip~, and bp~ to take pre-resolved buffers.
authored
74 default: break;
abb33ec First commit of current source.
Martin Roth authored
75 }
76 }
Something went wrong with that request. Please try again.