~ubuntu-branches/ubuntu/hoary/tap-plugins/hoary

« back to all changes in this revision

Viewing changes to tap_autopan.c

  • Committer: Bazaar Package Importer
  • Author(s): Anand Kumria
  • Date: 2004-07-19 02:32:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040719023250-hx31ef1lxjj6uns8
Tags: 0.6.0-1
* Many new upstream releases
* Documentation removed, it shall return.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*                                                     -*- linux-c -*-
2
2
    Copyright (C) 2004 Tom Szilagyi
3
3
    
 
4
    Patches were received from:
 
5
        Alexander Koenig <alex@lisas.de>
 
6
 
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.
17
20
 
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 $
19
22
*/
20
23
 
21
24
 
47
50
#define PORTCOUNT_STEREO   7
48
51
 
49
52
 
 
53
/* cosine table for fast computations */
 
54
LADSPA_Data cos_table[1024];
 
55
 
 
56
 
50
57
/* The structure used to hold port connection information and state */
51
58
 
52
59
typedef struct {
58
65
        LADSPA_Data * output_L;
59
66
        LADSPA_Data * output_R;
60
67
        unsigned long SampleRate;
61
 
        unsigned long Phase;
62
 
        LADSPA_Data cos_table[1024];
 
68
        LADSPA_Data Phase;
63
69
        LADSPA_Data run_adding_gain;
64
70
} AutoPan;
65
71
 
71
77
                    unsigned long             SampleRate) {
72
78
        
73
79
        LADSPA_Handle * ptr;
74
 
        int i;
75
80
        
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);
82
84
                return ptr;
83
85
        }
84
86
        
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;
151
153
        
152
154
        for (sample_index = 0; sample_index < SampleCount; sample_index++) {
153
 
                phase_L = 1024 * freq * sample_index / ptr->SampleRate + ptr->Phase;
154
 
                phase_L %= 1024;
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)
 
157
                        phase_L -= 1024.0f;  
 
158
                phase_R = phase_L + 512.0f;
 
159
                while (phase_R >= 1024.0f)
 
160
                        phase_R -= 1024.0f;  
156
161
 
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]);
161
166
        }
162
167
        ptr->Phase = phase_L;
 
168
        while (ptr->Phase >= 1024.0f)
 
169
                ptr->Phase -= 1024.0f;
163
170
}
164
171
 
165
172
 
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;
195
202
        
196
203
        for (sample_index = 0; sample_index < SampleCount; sample_index++) {
197
 
                phase_L = 1024 * freq * sample_index / ptr->SampleRate + ptr->Phase;
198
 
                phase_L %= 1024;
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)
 
206
                        phase_L -= 1024.0f;  
 
207
                phase_R = phase_L + 512.0f;
 
208
                while (phase_R >= 1024.0f)
 
209
                        phase_R -= 1024.0f;  
200
210
 
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]);
205
215
        }
206
216
        ptr->Phase = phase_L;
 
217
        while (ptr->Phase >= 1024.0f)
 
218
                ptr->Phase -= 1024.0f;
207
219
}
208
220
 
209
221
 
210
222
 
211
223
 
212
 
/* Throw away a AutoPan effect instance. */
 
224
/* Throw away an AutoPan effect instance. */
213
225
void 
214
226
cleanup_AutoPan(LADSPA_Handle Instance) {
215
227
        free(Instance);
226
238
void 
227
239
_init() {
228
240
        
 
241
        int i;
229
242
        char ** port_names;
230
243
        LADSPA_PortDescriptor * port_descriptors;
231
244
        LADSPA_PortRangeHint * port_range_hints;
234
247
             (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor))) == NULL)
235
248
                exit(1);
236
249
        
 
250
        for (i = 0; i < 1024; i++)
 
251
                cos_table[i] = cosf(i * M_PI / 512.0f);
237
252
 
238
253
 
239
254
        mono_descriptor->UniqueID = ID_STEREO;