LMMS
Loading...
Searching...
No Matches
delay.h
Go to the documentation of this file.
1/* Calf DSP Library
2 * Reusable audio effect classes.
3 *
4 * Copyright (C) 2001-2007 Krzysztof Foltman
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
20 */
21#ifndef __CALF_DELAY_H
22#define __CALF_DELAY_H
23
24#include "primitives.h"
25#include "buffer.h"
26#include "onepole.h"
27
28namespace dsp {
29
40template<int N, class T>
43 int pos;
44
46 reset();
47 }
48 void reset() {
49 pos = 0;
50 for (int i=0; i<N; i++)
51 zero(data[i]);
52 }
53
54 inline void put(T idata) {
55 data[pos] = idata;
57 }
58
66 template<class U>
67 inline void get(U &odata, int delay) {
68 assert(delay >= 0 && delay < N);
69 int ppos = wrap_around<N>(pos + N - delay);
70 odata = data[ppos];
71 }
72
76 inline T process(T idata, int delay)
77 {
78 assert(delay >= 0 && delay < N);
79 int ppos = wrap_around<N>(pos + N - delay);
80 T odata = data[ppos];
81 data[pos] = idata;
83 return odata;
84 }
85
93 template<class U>
94 inline void get_interp(U &odata, int delay, float udelay) {
95// assert(delay >= 0 && delay <= N-1);
96 int ppos = wrap_around<N>(pos + N - delay);
97 int pppos = wrap_around<N>(ppos + N - 1);
98 odata = lerp(data[ppos], data[pppos], udelay);
99 }
100
108 inline T get_interp_1616(unsigned int delay) {
109 float udelay = (float)((delay & 0xFFFF) * (1.0 / 65536.0));
110 delay = delay >> 16;
111// assert(delay >= 0 && delay < N-1);
112 int ppos = wrap_around<N>(pos + N - delay);
113 int pppos = wrap_around<N>(ppos + N - 1);
114 return lerp(data[ppos], data[pppos], udelay);
115 }
116
123 inline T process_comb(T in, unsigned int delay, float fb)
124 {
125 T old, cur;
126 get(old, delay);
127 cur = in + fb*old;
128 sanitize(cur);
129 put(cur);
130 return old;
131 }
132
140 inline T process_comb_lerp16(T in, unsigned int delay, float udelay, float fb)
141 {
142 T old, cur;
143 get_interp(old, delay>>16, dsp::fract16(delay));
144 cur = in + fb*old;
145 sanitize(cur);
146 put(cur);
147 return old;
148 }
149
156 inline T process_allpass_comb(T in, unsigned int delay, float fb)
157 {
158 T old, cur;
159 get(old, delay);
160 cur = in + fb*old;
161 sanitize(cur);
162 put(cur);
163 return old - fb * cur;
164 }
165
172 inline T process_allpass_comb_lerp16(T in, unsigned int delay, float fb)
173 {
174 T old, cur;
175 get_interp(old, delay>>16, dsp::fract16(delay));
176 cur = in + fb*old;
177 sanitize(cur);
178 put(cur);
179 return old - fb * cur;
180 }
181};
182
183};
184
185#endif
assert(0)
Definition buffer.h:106
register unsigned i
Definition inflate.c:1575
#define U(x)
Definition fmopl.c:132
float in
Definition lilv_test.c:1460
Definition audio_fx.h:36
T lerp(T v1, T v2, U mix)
Definition primitives.h:267
void zero(float &v)
Set a float to zero.
Definition primitives.h:41
int wrap_around(int a)
decrease by N if >= N (useful for circular buffers)
Definition buffer.h:27
float fract16(unsigned int value)
Definition primitives.h:415
void sanitize(float &value)
Definition primitives.h:354
#define N
Definition nseel-cfunc.c:36
simple_delay()
Definition delay.h:45
auto_buffer< N, T > data
Definition delay.h:42
int pos
Definition delay.h:43
T get_interp_1616(unsigned int delay)
Definition delay.h:108
void reset()
Definition delay.h:48
T process_comb_lerp16(T in, unsigned int delay, float udelay, float fb)
Definition delay.h:140
void get(U &odata, int delay)
Definition delay.h:67
T process(T idata, int delay)
Definition delay.h:76
void put(T idata)
Definition delay.h:54
T process_allpass_comb(T in, unsigned int delay, float fb)
Definition delay.h:156
T process_comb(T in, unsigned int delay, float fb)
Definition delay.h:123
void get_interp(U &odata, int delay, float udelay)
Definition delay.h:94
T process_allpass_comb_lerp16(T in, unsigned int delay, float fb)
Definition delay.h:172