Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/fluidsynth/src/rvoice/fluid_lfo.h
4396 views
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 Lesser General Public License
7
* as published by the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser 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 "fluid_sys.h"
25
26
typedef struct _fluid_lfo_t fluid_lfo_t;
27
28
struct _fluid_lfo_t
29
{
30
fluid_real_t val; /* the current value of the LFO */
31
unsigned int delay; /* the delay of the lfo in samples */
32
fluid_real_t increment; /* the lfo frequency is converted to a per-buffer increment */
33
};
34
35
static FLUID_INLINE void
36
fluid_lfo_reset(fluid_lfo_t *lfo)
37
{
38
lfo->val = 0.0f;
39
}
40
41
// These two cannot be inlined since they're used by event_dispatch
42
DECLARE_FLUID_RVOICE_FUNCTION(fluid_lfo_set_incr);
43
DECLARE_FLUID_RVOICE_FUNCTION(fluid_lfo_set_delay);
44
45
static FLUID_INLINE fluid_real_t
46
fluid_lfo_get_val(fluid_lfo_t *lfo)
47
{
48
return lfo->val;
49
}
50
51
static FLUID_INLINE void
52
fluid_lfo_calc(fluid_lfo_t *lfo, unsigned int cur_delay)
53
{
54
if(cur_delay < lfo->delay)
55
{
56
return;
57
}
58
59
lfo->val += lfo->increment;
60
61
if(lfo->val > (fluid_real_t) 1.0)
62
{
63
lfo->increment = -lfo->increment;
64
lfo->val = (fluid_real_t) 2.0 - lfo->val;
65
}
66
else if(lfo->val < (fluid_real_t) -1.0)
67
{
68
lfo->increment = -lfo->increment;
69
lfo->val = (fluid_real_t) -2.0 - lfo->val;
70
}
71
72
}
73
74
#endif
75
76