libnxter  0.1
HighPassFilter.nxc
Go to the documentation of this file.
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  HighPassFilter.nxc
4  Copyright (C) 2008 Naba Kumar <naba@gnome.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
26 #ifndef __HIGH_PASS_FILTER_H
27 #define __HIGH_PASS_FILTER_H
28 
33 {
34  int RC;
35  int alpha1000;
36  int lastInput;
37  int lastOutput;
38 };
39 
45 void
46 HighPassFilterInit (HighPassFilterContext &context, int RC, int samplingRate)
47 {
48  context.RC = RC;
49  /* alpha scaled by 1000 for int ops */
50  context.alpha1000 = (RC * samplingRate * 1000)/(RC * samplingRate + 1);
51  context.lastOutput = -1;
52  context.lastInput = -1;
53 }
54 
59 int
60 HighPassFilter (HighPassFilterContext &context, int sampleInput)
61 {
62  if (context.lastOutput < 0)
63  context.lastOutput = sampleInput;
64  else
65  context.lastOutput = context.alpha1000 * (context.lastOutput + sampleInput - context.lastInput);
66  context.lastOutput /= 1000; /* Scaled down from int ops */
67  context.lastInput = sampleInput;
68  return context.lastOutput;
69 }
70 
71 #endif
72 
void HighPassFilterInit(HighPassFilterContext &context, int RC, int samplingRate)
Initializes the given high pass filter context with the given RC constant and sampling rate...
High Pass filter contex.
int HighPassFilter(HighPassFilterContext &context, int sampleInput)
Steps through the filter using the current sample sampleInput. This must be called at the sampling ra...