3
Copyright (C) 2000 Jeff Tranter
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library 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.
11
This library 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
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
23
#include "artsmodules.h"
24
#include "stdsynthmodule.h"
28
// This delays the input signal for an amount of time. The time
29
// specification must be between 0 and 1 for a delay between 0 and 1
30
// second. The delay is constant during the calculation, that means it
31
// can't be modified. This saves computing time as no interpolation is
32
// done, and is useful for recursive structures. See the description
35
class Synth_CDELAY_impl : virtual public Synth_CDELAY_skel,
36
virtual public StdSynthModule
40
static const int SAMPLINGRATE = 44100;
41
static const int MAXDELAY = SAMPLINGRATE;
42
float *dbuffer; // holds one second of past data
47
dbuffer=new float[MAXDELAY];
54
float time() { return _time; }
56
void time(float newTime) { _time = newTime; }
60
// initialize buffer to all zeroes
61
for (int i=0; i < MAXDELAY; i++)
65
void calculateBlock(unsigned long samples)
67
// make sure delay is in range
68
if (_time < 0.0) _time = 0.0;
69
if (_time > 1.0) _time = 1.0;
71
// calculate delay in samples
72
unsigned long delay = (unsigned long) (_time * SAMPLINGRATE);
74
// Calculating output data
76
// 0 MAXDELAY 0 samples
77
// +------------------------+ +---------+
78
// | dbuffer | | invalue |
79
// +------------------------+ +---------+
86
for (unsigned long i=0; i<samples; i++)
89
outvalue[i] = invalue[i - delay];
91
outvalue[i] = dbuffer[MAXDELAY - delay + i];
94
// Updating delay buffer
96
// 0 MAXDELAY 0 samples
97
// +------------------------+ +---------+
98
// | dbuffer | | invalue |
99
// +------------------------+ +---------+
100
// +------------------------+
102
// +------------------------+
106
for (unsigned long i=0; i < MAXDELAY - samples; i++)
108
dbuffer[i] = dbuffer[i + samples];
111
// copy input buffer to the end of it
112
for (unsigned long i=0; i<samples; i++)
114
dbuffer[MAXDELAY - samples + i] = invalue[i];
119
REGISTER_IMPLEMENTATION(Synth_CDELAY_impl);