2 ==============================================================================
3 This file is part of Tal-Reverb by Patrick Kunz.
5 Copyright(c) 2005-2009 Patrick Kunz, TAL
9 This file may be licensed under the terms of of the
10 GNU General Public License Version 2 (the ``GPL'').
12 Software distributed under the License is distributed
13 on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14 express or implied. See the GPL for the specific language
15 governing rights and limitations.
17 You should have received a copy of the GPL along with this
18 program. If not, go to http://www.gnu.org/licenses/gpl.html
19 or write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 ==============================================================================
25 #if !defined(__CombFilter_h)
26 #define __CombFilter_h
29 #include "AudioUtils.h"
36 int readPtr1
, readPtr2
, writePtr
;
38 int bufferLengthDelay
;
41 AudioUtils audioUtils
;
44 // delay times in milliseconds
45 CombFilter(float delayTime
, float minDamp
, long samplingRate
)
47 //OutputDebugString("start init combfilter");
48 bufferLengthDelay
= (int)(delayTime
* samplingRate
/ 1000);
49 bufferLengthDelay
= audioUtils
.getNextNearPrime(bufferLengthDelay
);
50 buffer
= new float[bufferLengthDelay
];
53 //File *file = new File("d:/delaytimes.txt");
54 //String myXmlDoc = String((const int)bufferLengthDelay) << "\n";
55 //file->appendText(myXmlDoc);
57 //zero out the buffer (silence)
58 for (int i
= 0; i
< bufferLengthDelay
; i
++)
63 //set read pointer to start of buffer
65 z1
= filterStore
= 0.0f
;
66 this->minDamp
= minDamp
;
67 //OutputDebugString("end init combfilter");
75 // delayIntensity [0..1]
76 inline float processInterpolated(float input
, float damp
, float feedback
, float delay
)
78 float offset
= (bufferLengthDelay
- 2) * delay
+ 1.0f
;
79 readPtr1
= writePtr
- (int)floorf(offset
);
82 readPtr1
+= bufferLengthDelay
;
84 readPtr2
= readPtr1
- 1;
86 readPtr2
+= bufferLengthDelay
;
88 // interpolate, see paper: http://www.stanford.edu/~dattorro/EffectDesignPart2.pdf
89 float frac
= offset
- (int)floorf(offset
);
90 float output
= buffer
[readPtr2
] + buffer
[readPtr1
] * (1-frac
) - (1-frac
) * z1
;
93 damp
= minDamp
* damp
;
94 filterStore
= output
* (1.0f
- damp
) + filterStore
* damp
;
95 buffer
[writePtr
] = input
+ (filterStore
* feedback
);
97 if (++writePtr
>= bufferLengthDelay
)
102 inline float process(float input
, float damp
, float feedback
, float delay
)
104 float offset
= (bufferLengthDelay
- 2) * delay
+ 1.0f
;
105 readPtr1
= writePtr
- (int)floorf(offset
);
108 readPtr1
+= bufferLengthDelay
;
110 float output
= buffer
[readPtr1
];
111 filterStore
= output
* (1.0f
- damp
) + filterStore
* damp
;
112 buffer
[writePtr
] = input
+ (filterStore
* feedback
);
114 if (++writePtr
>= bufferLengthDelay
)