CSL
5.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Freeverb.h
Go to the documentation of this file.
1
//
2
// Reverb.h -- The CSL port of the public domain Freeverb reverberator
3
// Freeverb was written by Jezar at Dreampoint, June 2000 -- http://www.dreampoint.co.uk
4
// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
5
//
6
7
#ifndef CSL_Reverb_H
8
#define CSL_Reverb_H
9
10
#include "
CSL_Core.h
"
11
12
#define undenormalise(samplev) if (((*(unsigned int*)&samplev)&0x7f800000) == 0) samplev = 0.0f
13
14
namespace
csl {
15
16
class
Comb;
// predeclaration of utility classes
17
class
FAllpass;
18
19
///
20
/// CSL port of the public domain Freeverb reverberator
21
///
22
23
class
Freeverb
:
public
Effect
,
public
Scalable
{
24
25
public
:
26
Freeverb
(
UnitGenerator
&input);
27
~Freeverb
();
28
29
float
roomSize
();
30
void
setRoomSize
(
float
size);
///< Setting the room size makes longer tails. The value has a range from 0 to 1.
31
float
dampening
();
32
void
setDampening
(
float
damp);
///< Specified in percentage (from 0 to 100%).
33
float
wetLevel
();
34
void
setWetLevel
(
float
level);
///< Amount of wet (reverberation) in the mixed output.
35
float
dryLevel
();
36
void
setDryLevel
(
float
level);
///< Amount of the original "dry" signal in the output.
37
float
width
();
38
void
setWidth
(
float
width);
///< Currently not used, as this reverb became mono in/out.
39
40
void
nextBuffer
(
Buffer
&outputBuffer,
unsigned
outBufNum)
throw
(
CException
);
41
42
protected
:
// accessable parameters
43
float
mRoomSize
;
44
float
mDampening
;
45
float
mWetLevel
;
46
float
mDryLevel
;
47
float
mWidth
;
48
// internal parameters
49
float
mGain
;
50
51
std::vector <Comb *>
mCombFilters
;
52
std::vector <FAllpass *>
mAllpassFilters
;
53
54
SampleBufferVector
mCombBuffers
;
55
SampleBufferVector
mAllpassBuffers
;
56
57
void
constructReverbGraph
();
58
void
updateParameters
();
59
};
60
61
///
62
/// Comb filter class
63
///
64
65
class
Comb
{
66
public
:
67
Comb
() :
mFilterStore
(0),
mBufIdx
(0) { };
68
69
void
mute
();
70
float
damp
() {
return
mDamp1
; }
71
float
feedback
() {
return
mFeedback
; }
72
void
setDamp
(
float
val);
73
void
setFeedback
(
float
val) {
mFeedback
= val; }
74
void
setBuffer
(
float
*buf,
int
size);
75
76
inline
float
process
(
float
inp);
77
78
private
:
79
float
mFeedback
;
80
float
mFilterStore
;
81
float
mDamp1
;
82
float
mDamp2
;
83
float
*
mBufferPtr
;
84
int
mBufSize
;
85
int
mBufIdx
;
86
};
87
88
///
89
/// All-pass filter class
90
///
91
92
class
FAllpass
{
93
public
:
94
FAllpass
() :
mBufIdx
(0) { };
95
96
void
mute
();
97
float
feedback
() {
return
mFeedback
; };
98
void
setFeedback
(
float
val) {
mFeedback
= val; };
99
void
setBuffer
(
float
*buf,
int
size);
100
101
inline
float
process
(
float
inp);
102
103
private
:
104
float
mFeedback
;
105
float
*
mBufferPtr
;
106
int
mBufSize
;
107
int
mBufIdx
;
108
};
109
110
// Big to inline - but crucial for speed
111
112
inline
float
Comb::process
(
float
input) {
113
float
output =
mBufferPtr
[
mBufIdx
];
114
undenormalise
(output);
115
mFilterStore
= (output *
mDamp2
) + (
mFilterStore
*
mDamp1
);
116
undenormalise
(
mFilterStore
);
117
mBufferPtr
[
mBufIdx
] = input + (
mFilterStore
*
mFeedback
);
118
if
(++
mBufIdx
>=
mBufSize
)
119
mBufIdx
= 0;
120
return
output;
121
}
122
123
inline
float
FAllpass::process
(
float
input) {
124
float
bufout =
mBufferPtr
[
mBufIdx
];
125
undenormalise
(bufout);
126
float
output = -input + bufout;
127
mBufferPtr
[
mBufIdx
] = input + (bufout *
mFeedback
);
128
if
(++
mBufIdx
>=
mBufSize
)
129
mBufIdx
= 0;
130
return
output;
131
}
132
133
///
134
// Stereoverb is a simple wrapper around 2 freeverbs with splitter/joiners
135
// for handling stereo inputs - note the overrides of isActive() and numchannels()
136
///
137
138
class
Stereoverb
:
public
Effect
{
139
140
public
:
141
Stereoverb
(
UnitGenerator
& input);
142
~Stereoverb
();
143
144
void
setRoomSize
(
float
size);
145
void
setDampening
(
float
damp);
146
void
setWetLevel
(
float
level);
147
void
setDryLevel
(
float
level);
148
void
setWidth
(
float
width);
149
bool
isActive
();
150
unsigned
numChannels
() {
return
2; };
///< I'm stereo
151
152
void
nextBuffer
(
Buffer
&outputBuffer)
throw
(
CException
);
153
154
protected
:
155
Freeverb
*
leftRev
, *
rightRev
;
// 2 mono reverberators
156
Splitter
*
split
;
// stereo-to-mono splitter
157
Joiner
*
join
;
// mono-to-stereo joiner
158
};
159
160
}
161
162
#endif
CSL
Processors
Freeverb.h
Generated on Thu Nov 15 2012 22:01:10 for CSL by
1.8.1.1