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(__AllPassFilter_h)
26 #define __AllPassFilter_h
29 #include "AudioUtils.h"
36 int bufferLength
, writePtr
, readPtr1
, readPtr2
;
39 AudioUtils audioUtils
;
42 // delay times in milliseconds
43 AllPassFilter(float delayTime
, float feedbackGain
, long samplingRate
)
45 //OutputDebugString("start init allPass");
49 bufferLength
= (int)(delay
* samplingRate
/ 1000.0f
);
50 bufferLength
= audioUtils
.getNextNearPrime(bufferLength
);
51 buffer
= new float[bufferLength
];
53 //zero out the buffer (create silence)
54 for (int i
= 0; i
< bufferLength
; i
++)
57 writePtr
= readPtr1
= readPtr2
= 0;
59 //OutputDebugString("end init allPass");
68 inline float processInterpolated(float input
, float delayLength
, float diffuse
, bool negative
)
70 // dynamic interpolated
71 float offset
= (bufferLength
- 2.0f
) * delayLength
+ 1.0f
;
72 readPtr1
= writePtr
- (int)floorf(offset
);
75 readPtr1
+= bufferLength
;
77 readPtr2
= readPtr1
- 1;
79 readPtr2
+= bufferLength
;
81 // interpolate, see paper: http://www.stanford.edu/~dattorro/EffectDesignPart2.pdf
82 float frac
= offset
- (int)floorf(offset
);
83 float temp
= buffer
[readPtr2
] + buffer
[readPtr1
] * (1-frac
) - (1-frac
) * z1
;
89 buffer
[writePtr
] = diffuse
* gain
* temp
+ input
;
90 output
= temp
- diffuse
* gain
* buffer
[writePtr
];
94 buffer
[writePtr
] = diffuse
* gain
* temp
- input
;
95 output
= temp
+ diffuse
* gain
* buffer
[writePtr
];
98 if (++writePtr
>= bufferLength
)
104 inline float process(float input
, float diffuse
)
106 float temp
= buffer
[readPtr1
];
107 buffer
[readPtr1
] = diffuse
* gain
* temp
+ input
;
108 float output
= temp
- diffuse
* gain
* buffer
[readPtr1
];
110 if (++readPtr1
>= bufferLength
)
116 inline float process(float input
)
118 float temp
= buffer
[readPtr1
];
119 buffer
[readPtr1
] = gain
* temp
+ input
;
120 float output
= temp
- gain
* buffer
[readPtr1
];
122 if (++readPtr1
>= bufferLength
)