LMMS
Loading...
Searching...
No Matches
gverb.h
Go to the documentation of this file.
1/*
2
3 Copyright (C) 1999 Juhana Sadeharju
4 kouhia at nic.funet.fi
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21
22#ifndef GVERB_H
23#define GVERB_H
24
25#include <stdlib.h>
26#include <math.h>
27#include <string.h>
28#include "gverbdsp.h"
29#include "../ladspa-util.h"
30
31#define FDNORDER 4
32
59
60
61ty_gverb *gverb_new(int, float, float, float, float, float, float, float, float);
62void gverb_free(ty_gverb *);
63void gverb_flush(ty_gverb *);
64static void gverb_do(ty_gverb *, float, float *, float *);
65static void gverb_set_roomsize(ty_gverb *, float);
66static void gverb_set_revtime(ty_gverb *, float);
67static void gverb_set_damping(ty_gverb *, float);
68static void gverb_set_inputbandwidth(ty_gverb *, float);
69static void gverb_set_earlylevel(ty_gverb *, float);
70static void gverb_set_taillevel(ty_gverb *, float);
71
72/*
73 * This FDN reverb can be made smoother by setting matrix elements at the
74 * diagonal and near of it to zero or nearly zero. By setting diagonals to zero
75 * means we remove the effect of the parallel comb structure from the
76 * reverberation. A comb generates uniform impulse stream to the reverberation
77 * impulse response, and thus it is not good. By setting near diagonal elements
78 * to zero means we remove delay sequences having consequtive delays of the
79 * similar lenths, when the delays are in sorted in length with respect to
80 * matrix element index. The matrix described here could be generated by
81 * differencing Rocchesso's circulant matrix at max diffuse value and at low
82 * diffuse value (approaching parallel combs).
83 *
84 * Example 1:
85 * Set a(k,k), for all k, equal to 0.
86 *
87 * Example 2:
88 * Set a(k,k), a(k,k-1) and a(k,k+1) equal to 0.
89 *
90 * Example 3: The transition to zero gains could be smooth as well.
91 * a(k,k-1) and a(k,k+1) could be 0.3, and a(k,k-2) and a(k,k+2) could
92 * be 0.5, say.
93 */
94
95static inline void gverb_fdnmatrix(float *a, float *b)
96{
97 const float dl0 = a[0], dl1 = a[1], dl2 = a[2], dl3 = a[3];
98
99 b[0] = 0.5f*(+dl0 + dl1 - dl2 - dl3);
100 b[1] = 0.5f*(+dl0 - dl1 - dl2 + dl3);
101 b[2] = 0.5f*(-dl0 + dl1 - dl2 + dl3);
102 b[3] = 0.5f*(+dl0 + dl1 + dl2 + dl3);
103}
104
105static inline void gverb_do(ty_gverb *p, float x, float *yl, float *yr)
106{
107 float z;
108 unsigned int i;
109 float lsum,rsum,sum,sign;
110
111 if (isnan(x) || fabsf(x) > 100000.0f) {
112 x = 0.0f;
113 }
114
115 z = damper_do(p->inputdamper, x);
116
117 z = diffuser_do(p->ldifs[0],z);
118
119 for(i = 0; i < FDNORDER; i++) {
120 p->u[i] = p->tapgains[i]*fixeddelay_read(p->tapdelay,p->taps[i]);
121 }
122 fixeddelay_write(p->tapdelay,z);
123
124 for(i = 0; i < FDNORDER; i++) {
125 p->d[i] = damper_do(p->fdndamps[i],
126 p->fdngains[i]*fixeddelay_read(p->fdndels[i],
127 p->fdnlens[i]));
128 }
129
130 sum = 0.0f;
131 sign = 1.0f;
132 for(i = 0; i < FDNORDER; i++) {
133 sum += sign*(p->taillevel*p->d[i] + p->earlylevel*p->u[i]);
134 sign = -sign;
135 }
136 sum += x*p->earlylevel;
137 lsum = sum;
138 rsum = sum;
139
140 gverb_fdnmatrix(p->d,p->f);
141
142 for(i = 0; i < FDNORDER; i++) {
143 fixeddelay_write(p->fdndels[i],p->u[i]+p->f[i]);
144 }
145
146 lsum = diffuser_do(p->ldifs[1],lsum);
147 lsum = diffuser_do(p->ldifs[2],lsum);
148 lsum = diffuser_do(p->ldifs[3],lsum);
149 rsum = diffuser_do(p->rdifs[1],rsum);
150 rsum = diffuser_do(p->rdifs[2],rsum);
151 rsum = diffuser_do(p->rdifs[3],rsum);
152
153 *yl = lsum;
154 *yr = rsum;
155}
156
157static inline void gverb_set_roomsize(ty_gverb *p, const float a)
158{
159 unsigned int i;
160
161 if (a <= 1.0 || isnan(a)) {
162 p->roomsize = 1.0;
163 } else {
164 p->roomsize = a;
165 }
166 p->largestdelay = p->rate * p->roomsize * 0.00294f;
167
168 p->fdnlens[0] = f_round(1.000000f*p->largestdelay);
169 p->fdnlens[1] = f_round(0.816490f*p->largestdelay);
170 p->fdnlens[2] = f_round(0.707100f*p->largestdelay);
171 p->fdnlens[3] = f_round(0.632450f*p->largestdelay);
172 for(i = 0; i < FDNORDER; i++) {
173 p->fdngains[i] = -powf((float)p->alpha, p->fdnlens[i]);
174 }
175
176 p->taps[0] = 5+f_round(0.410f*p->largestdelay);
177 p->taps[1] = 5+f_round(0.300f*p->largestdelay);
178 p->taps[2] = 5+f_round(0.155f*p->largestdelay);
179 p->taps[3] = 5+f_round(0.000f*p->largestdelay);
180
181 for(i = 0; i < FDNORDER; i++) {
182 p->tapgains[i] = powf((float)p->alpha, p->taps[i]);
183 }
184
185}
186
187static inline void gverb_set_revtime(ty_gverb *p,float a)
188{
189 float ga,gt;
190 double n;
191 unsigned int i;
192
193 p->revtime = a;
194
195 ga = 60.0;
196 gt = p->revtime;
197 ga = powf(10.0f,-ga/20.0f);
198 n = p->rate*gt;
199 p->alpha = (double)powf(ga,1.0f/n);
200
201 for(i = 0; i < FDNORDER; i++) {
202 p->fdngains[i] = -powf((float)p->alpha, p->fdnlens[i]);
203 }
204
205}
206
207static inline void gverb_set_damping(ty_gverb *p,float a)
208{
209 unsigned int i;
210
211 p->fdndamping = a;
212 for(i = 0; i < FDNORDER; i++) {
213 damper_set(p->fdndamps[i],p->fdndamping);
214 }
215}
216
217static inline void gverb_set_inputbandwidth(ty_gverb *p,float a)
218{
219 p->inputbandwidth = a;
220 damper_set(p->inputdamper,1.0 - p->inputbandwidth);
221}
222
223static inline void gverb_set_earlylevel(ty_gverb *p,float a)
224{
225 p->earlylevel = a;
226}
227
228static inline void gverb_set_taillevel(ty_gverb *p,float a)
229{
230 p->taillevel = a;
231}
232
233#endif
uint8_t a
Definition Spc_Cpu.h:141
unsigned z
Definition inflate.c:1589
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
static void gverb_fdnmatrix(float *a, float *b)
Definition gverb.h:95
static void gverb_set_taillevel(ty_gverb *, float)
Definition gverb.h:228
void gverb_flush(ty_gverb *)
Definition gverb.c:190
static void gverb_set_damping(ty_gverb *, float)
Definition gverb.h:207
static void gverb_set_revtime(ty_gverb *, float)
Definition gverb.h:187
static void gverb_do(ty_gverb *, float, float *, float *)
Definition gverb.h:105
#define FDNORDER
Definition gverb.h:31
void gverb_free(ty_gverb *)
Definition gverb.c:164
static void gverb_set_inputbandwidth(ty_gverb *, float)
Definition gverb.h:217
static void gverb_set_roomsize(ty_gverb *, float)
Definition gverb.h:157
static void gverb_set_earlylevel(ty_gverb *, float)
Definition gverb.h:223
ty_gverb * gverb_new(int, float, float, float, float, float, float, float, float)
Definition gverb.c:31
static float damper_do(ty_damper *p, float x)
Definition gverbdsp.h:76
static void damper_set(ty_damper *p, float damping)
Definition gverbdsp.h:71
static float diffuser_do(ty_diffuser *p, float x)
Definition gverbdsp.h:45
static void fixeddelay_write(ty_fixeddelay *p, float x)
Definition gverbdsp.h:65
static float fixeddelay_read(ty_fixeddelay *p, int n)
Definition gverbdsp.h:57
static int f_round(float f)
Definition ladspa-util.h:175
Definition gverbdsp.h:20
Definition gverbdsp.h:13
Definition gverbdsp.h:7
Definition gverb.h:33
float taillevel
Definition gverb.h:36
float * d
Definition gverb.h:54
ty_diffuser ** ldifs
Definition gverb.h:49
float largestdelay
Definition gverb.h:43
double alpha
Definition gverb.h:57
ty_diffuser ** rdifs
Definition gverb.h:50
float * u
Definition gverb.h:55
ty_damper * inputdamper
Definition gverb.h:38
int * fdnlens
Definition gverb.h:46
float * fdngains
Definition gverb.h:45
float earlylevel
Definition gverb.h:37
float inputbandwidth
Definition gverb.h:35
ty_fixeddelay * tapdelay
Definition gverb.h:51
float maxdelay
Definition gverb.h:42
float * tapgains
Definition gverb.h:53
ty_fixeddelay ** fdndels
Definition gverb.h:44
float maxroomsize
Definition gverb.h:39
int * taps
Definition gverb.h:52
float * f
Definition gverb.h:56
int rate
Definition gverb.h:34
ty_damper ** fdndamps
Definition gverb.h:47
float roomsize
Definition gverb.h:40
float fdndamping
Definition gverb.h:48
float revtime
Definition gverb.h:41
int n
Definition crypt.c:458
uch * p
Definition crypt.c:594
b
Definition crypt.c:628
yr
Definition zipinfo.c:2302