Configure the new 'fluidsynth' library to be buildable with MSVC
[ardour.git] / libs / fluidsynth / src / fluid_lfo.h
1 /* FluidSynth - A Software Synthesizer
2  *
3  * Copyright (C) 2003  Peter Hanappe and others.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * as published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA
19  */
20
21 #ifndef _FLUID_LFO_H
22 #define _FLUID_LFO_H
23
24 #include "fluidsynth_priv.h"
25
26 typedef struct _fluid_lfo_t fluid_lfo_t;
27
28 struct _fluid_lfo_t {
29         fluid_real_t val;          /* the current value of the LFO */
30         unsigned int delay;       /* the delay of the lfo in samples */
31         fluid_real_t increment;         /* the lfo frequency is converted to a per-buffer increment */
32 };
33
34 static inline void 
35 fluid_lfo_reset(fluid_lfo_t* lfo)
36 {
37   lfo->val = 0.0f;
38 }
39
40 // These two cannot be inlined since they're used by event_dispatch
41 void fluid_lfo_set_incr(fluid_lfo_t* lfo, fluid_real_t increment);
42 void fluid_lfo_set_delay(fluid_lfo_t* lfo, unsigned int delay);
43
44 static inline fluid_real_t
45 fluid_lfo_get_val(fluid_lfo_t* lfo)
46 {
47   return lfo->val;
48 }
49
50 static inline void 
51 fluid_lfo_calc(fluid_lfo_t* lfo, unsigned int cur_delay)
52 {
53   if (cur_delay < lfo->delay) 
54     return;
55   
56   lfo->val += lfo->increment;
57   
58   if (lfo->val > (fluid_real_t) 1.0)
59   {
60     lfo->increment = -lfo->increment;
61     lfo->val = (fluid_real_t) 2.0 - lfo->val;
62   }
63   else if (lfo->val < (fluid_real_t) -1.0)
64   {
65     lfo->increment = -lfo->increment;
66     lfo->val = (fluid_real_t) -2.0 - lfo->val;
67   }
68
69 }
70
71 #endif
72