Merged annhell-branch-float into trunk.
[ahxm.git] / effect.c
blob9c0ebda43a79249c4375adad37106029051be76b
1 /*
3 PROGRAM_NAME PROGRAM_VERSION - PROGRAM_DESCRIPTION
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
25 #include "config.h"
27 #include <stdlib.h>
28 #include <math.h>
30 #include "core.h"
31 #include "effect.h"
33 /*******************
34 Data
35 ********************/
37 /*******************
38 Code
39 ********************/
41 void init_delay(struct effect_delay * e, int size, float gain,
42 double depth, double lfo_freq, double llfo, double rlfo)
44 int n;
46 e->lbuffer=(float *) malloc(size * sizeof(float));
47 e->rbuffer=(float *) malloc(size * sizeof(float));
49 for(n=0;n < size;n++)
50 e->lbuffer[n]=e->rbuffer[n]=0;
52 e->size=size;
53 e->gain=gain;
54 e->depth=depth;
55 e->lfo_freq=lfo_freq;
56 e->llfo=llfo;
57 e->rlfo=rlfo;
59 /* calculates lfo increment */
60 e->lfo_inc=(lfo_freq * 6.28) / (double) _frequency;
62 e->cursor=0;
66 void process_delay(struct effect_delay * e, float * lsample, float * rsample)
68 float l,r;
70 l=e->lbuffer[e->cursor] * e->gain;
71 r=e->lbuffer[e->cursor] * e->gain;
73 e->lbuffer[e->cursor]=*lsample;
74 e->rbuffer[e->cursor]=*rsample;
76 if(++e->cursor == e->size) e->cursor=0;
78 *lsample+=l;
79 *rsample+=r;
83 void process_comb(struct effect_delay * e, float * lsample, float * rsample)
85 float l,r;
87 l=e->lbuffer[e->cursor];
88 r=e->lbuffer[e->cursor];
90 e->lbuffer[e->cursor]=*lsample + (l * e->gain);
91 e->rbuffer[e->cursor]=*rsample + (r * e->gain);
93 if(++e->cursor == e->size) e->cursor=0;
95 *lsample+=l;
96 *rsample+=r;
100 void process_flanger(struct effect_delay * e, float * lsample, float * rsample)
102 float l,r;
103 double s,c;
105 s=(double) e->size;
107 c=(double) e->cursor - e->depth;
108 c-=e->depth * sin(e->llfo);
109 e->llfo += e->lfo_inc;
110 if(c < 0) c+=s;
112 l=get_sample(e->lbuffer, s, c) * e->gain;
114 c=(double) e->cursor - e->depth;
115 c-=e->depth * sin(e->rlfo);
116 e->rlfo += e->lfo_inc;
117 if(c < 0) c+=s;
119 r=get_sample(e->rbuffer, s, c) * e->gain;
121 e->lbuffer[e->cursor]=*lsample;
122 e->rbuffer[e->cursor]=*rsample;
124 if(++e->cursor == e->size) e->cursor=0;
126 *lsample+=l;
127 *rsample+=r;