Nsound  0.9.4
FilterDC.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------////
2 //
3 // $Id: FilterDC.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2007 Nick Hilton
6 //
7 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
8 //
9 //-----------------------------------------------------------------------------////
10 
11 //-----------------------------------------------------------------------------////
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 //
27 //-----------------------------------------------------------------------------////
28 
29 #include <Nsound/AudioStream.h>
30 #include <Nsound/Buffer.h>
31 #include <Nsound/FilterDC.h>
32 
33 using namespace Nsound;
34 
35 //-----------------------------------------------------------------------------
37 FilterDC(const float64 & feedback_gain)
38  :
39  feedback_gain_(feedback_gain),
40  last_input_(0.0),
41  last_output_(0.0)
42 {
43 }
44 
47 filter(const AudioStream & x)
48 {
49  uint32 n_channels = x.getNChannels();
50 
51  AudioStream y(x.getSampleRate(), n_channels);
52 
53  for(uint32 channel = 0; channel < n_channels; ++channel)
54  {
55  y[channel] = filter(x[channel]);
56  }
57 
58  return y;
59 }
60 
61 
62 Buffer
64 filter(const Buffer & x)
65 {
66  uint32 n_samples = x.getLength();
67 
68  Buffer y;
69 
70  for(uint32 n = 0; n < n_samples; ++n)
71  {
72  y << filter(x[n]);
73  }
74 
75  return y;
76 }
77 
78 float64
80 filter(const float64 & x)
81 {
83 
84  last_input_ = x;
85  last_output_ = out;
86 
87  return out;
88 }
89 
unsigned int uint32
Definition: Nsound.h:153
FilterDC(const float64 &feedback_gain)
Definition: FilterDC.cc:37
float64 feedback_gain_
Definition: FilterDC.h:67
float64 getSampleRate() const
Returns the sample rate of the stream.
Definition: AudioStream.h:217
double float64
Definition: Nsound.h:146
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
Definition: AudioStream.h:212
float64 last_input_
Definition: FilterDC.h:68
A Buffer for storing audio samples.
Definition: Buffer.h:60
float64 last_output_
Definition: FilterDC.h:69
AudioStream filter(const AudioStream &x)
Definition: FilterDC.cc:47