File: Chorus.cc

package info (click to toggle)
caps 0.9.26-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 924 kB
  • sloc: cpp: 10,867; ansic: 1,324; makefile: 78; python: 38
file content (124 lines) | stat: -rw-r--r-- 2,587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
	Chorus.cc
	
	Copyright 2004-13 Tim Goetze <tim@quitte.de>
	
	http://quitte.de/dsp/

	Chorus units.
	
*/
/*
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 3
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
	02111-1307, USA or point your web browser to http://www.gnu.org.
*/

#include "basics.h"

#include "Chorus.h"
#include "Descriptor.h"

void
ChorusI::activate()
{
	setrate (getport(0));
	time = 0;
	width = 0;
	delay.reset();
	hp.reset();
	hp.set_f(250*over_fs);
}

void
ChorusI::setrate (float r)
{
	if (r == rate) return;
	rate = r;
	lfo.sine.set_f (rate, fs, lfo.sine.get_phase());
}

void
ChorusI::cycle (uint frames)
{
	float one_over_n = 1/(float)frames;
	float ms = fs*.001;

	float t = time;
	time = getport(0)*ms;
	float dt = (time - t)*one_over_n;

	float w = width;
	width = getport(1)*ms;
	/* clamp, or we need future samples from the delay line */
	if (width >= t - 3) width = t - 3;
	float dw = (width - w) * one_over_n;

	setrate (getport(2));
	
	float blend = getport(3);
	float ff = getport(4);
	float fb = getport(5);

	sample_t * s = ports[6];
	sample_t * d = ports[7];

	DSP::FPTruncateMode truncate;

	for (uint i = 0; i < frames; ++i)
	{
		sample_t x=s[i], y=x;

		x = hp.process(x+normal);

		y -= fb*delay.get_linear(t);

		delay.put (y + normal);

		y += blend*x + ff*delay.get_cubic (t + w*lfo.sine.get());

		d[i] = y;

		t += dt;
		w += dw;
	}
}

/* //////////////////////////////////////////////////////////////////////// */

PortInfo
ChorusI::port_info [] =
{
	{ "t (ms)", CTRL_IN, {LOG | DEFAULT_MID, 2.5, 40} }, 
	{ "width (ms)", CTRL_IN, {DEFAULT_LOW, .5, 10} }, 

	{ "rate (Hz)", CTRL_IN | GROUP, {LOG | DEFAULT_LOW, 0.02, 5} }, 

	{ "blend", CTRL_IN | GROUP, {DEFAULT_LOW, 0, 1} }, 
	{ "feedforward", CTRL_IN, {DEFAULT_LOW, 0, 1} }, 
	{ "feedback", CTRL_IN, {DEFAULT_LOW, 0, 1} }, 

	{ "in", INPUT | AUDIO }, 
	{ "out", OUTPUT | AUDIO }
};

template <> void
Descriptor<ChorusI>::setup()
{
	Label = "ChorusI";
	Name = CAPS "ChorusI - Mono chorus/flanger";
	autogen();
}