2
2
Copyright (C) 2004 Tom Szilagyi
4
Patches were received from:
5
Alexander Koenig <alex@lisas.de>
4
7
This program is free software; you can redistribute it and/or modify
5
8
it under the terms of the GNU General Public License as published by
6
9
the Free Software Foundation; either version 2 of the License, or
15
18
along with this program; if not, write to the Free Software
16
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
$Id: tap_autopan.c,v 1.1 2004/02/01 19:38:25 tszilagyi Exp $
21
$Id: tap_autopan.c,v 1.6 2004/02/21 17:33:36 tszilagyi Exp $
71
77
unsigned long SampleRate) {
73
79
LADSPA_Handle * ptr;
76
81
if ((ptr = malloc(sizeof(AutoPan))) != NULL) {
77
82
((AutoPan *)ptr)->SampleRate = SampleRate;
78
83
((AutoPan *)ptr)->run_adding_gain = 1.0;
79
for (i = 0; i < 1024; i++)
80
((AutoPan *)ptr)->cos_table[i] =
81
cosf(i * M_PI / 512.0f);
142
144
LADSPA_Data * input_R = ptr->input_R;
143
145
LADSPA_Data * output_L = ptr->output_L;
144
146
LADSPA_Data * output_R = ptr->output_R;
145
LADSPA_Data freq = *(ptr->freq);
146
LADSPA_Data depth = *(ptr->depth);
147
LADSPA_Data gain = db2lin(*(ptr->gain));
147
LADSPA_Data freq = LIMIT(*(ptr->freq),0.0f,20.0f);
148
LADSPA_Data depth = LIMIT(*(ptr->depth),0.0f,100.0f);
149
LADSPA_Data gain = db2lin(LIMIT(*(ptr->gain),-70.0f,20.0f));
148
150
unsigned long sample_index;
149
unsigned long phase_L = 0;
150
unsigned long phase_R = 0;
151
LADSPA_Data phase_L = 0;
152
LADSPA_Data phase_R = 0;
152
154
for (sample_index = 0; sample_index < SampleCount; sample_index++) {
153
phase_L = 1024 * freq * sample_index / ptr->SampleRate + ptr->Phase;
155
phase_R = (phase_L + 512) % 1024;
155
phase_L = 1024.0f * freq * sample_index / ptr->SampleRate + ptr->Phase;
156
while (phase_L >= 1024.0f)
158
phase_R = phase_L + 512.0f;
159
while (phase_R >= 1024.0f)
157
162
*(output_L++) = *(input_L++) * gain *
158
(1 - 0.5*depth/100 + 0.5 * depth/100 * ptr->cos_table[phase_L]);
163
(1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase_L]);
159
164
*(output_R++) = *(input_R++) * gain *
160
(1 - 0.5*depth/100 + 0.5 * depth/100 * ptr->cos_table[phase_R]);
165
(1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase_R]);
162
167
ptr->Phase = phase_L;
168
while (ptr->Phase >= 1024.0f)
169
ptr->Phase -= 1024.0f;
186
193
LADSPA_Data * input_R = ptr->input_R;
187
194
LADSPA_Data * output_L = ptr->output_L;
188
195
LADSPA_Data * output_R = ptr->output_R;
189
LADSPA_Data freq = *(ptr->freq);
190
LADSPA_Data depth = *(ptr->depth);
191
LADSPA_Data gain = db2lin(*(ptr->gain));
196
LADSPA_Data freq = LIMIT(*(ptr->freq),0.0f,20.0f);
197
LADSPA_Data depth = LIMIT(*(ptr->depth),0.0f,100.0f);
198
LADSPA_Data gain = db2lin(LIMIT(*(ptr->gain),-70.0f,20.0f));
192
199
unsigned long sample_index;
193
unsigned long phase_L = 0;
194
unsigned long phase_R = 0;
200
LADSPA_Data phase_L = 0;
201
LADSPA_Data phase_R = 0;
196
203
for (sample_index = 0; sample_index < SampleCount; sample_index++) {
197
phase_L = 1024 * freq * sample_index / ptr->SampleRate + ptr->Phase;
199
phase_R = (phase_L + 512) % 1024;
204
phase_L = 1024.0f * freq * sample_index / ptr->SampleRate + ptr->Phase;
205
while (phase_L >= 1024.0f)
207
phase_R = phase_L + 512.0f;
208
while (phase_R >= 1024.0f)
201
211
*(output_L++) += *(input_L++) * gain * ptr->run_adding_gain *
202
(1 - 0.5*depth/100 + 0.5 * depth/100 * ptr->cos_table[phase_L]);
212
(1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase_L]);
203
213
*(output_R++) += *(input_R++) * gain * ptr->run_adding_gain *
204
(1 - 0.5*depth/100 + 0.5 * depth/100 * ptr->cos_table[phase_R]);
214
(1 - 0.5*depth/100 + 0.5 * depth/100 * cos_table[(unsigned long) phase_R]);
206
216
ptr->Phase = phase_L;
217
while (ptr->Phase >= 1024.0f)
218
ptr->Phase -= 1024.0f;
212
/* Throw away a AutoPan effect instance. */
224
/* Throw away an AutoPan effect instance. */
214
226
cleanup_AutoPan(LADSPA_Handle Instance) {