1 /* FluidSynth - A Software Synthesizer
3 * Copyright (C) 2003 Peter Hanappe and others.
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.
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.
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
24 #include "fluidsynth_priv.h"
26 typedef struct _fluid_lfo_t 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 */
35 fluid_lfo_reset(fluid_lfo_t* lfo)
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);
44 static inline fluid_real_t
45 fluid_lfo_get_val(fluid_lfo_t* lfo)
51 fluid_lfo_calc(fluid_lfo_t* lfo, unsigned int cur_delay)
53 if (cur_delay < lfo->delay)
56 lfo->val += lfo->increment;
58 if (lfo->val > (fluid_real_t) 1.0)
60 lfo->increment = -lfo->increment;
61 lfo->val = (fluid_real_t) 2.0 - lfo->val;
63 else if (lfo->val < (fluid_real_t) -1.0)
65 lfo->increment = -lfo->increment;
66 lfo->val = (fluid_real_t) -2.0 - lfo->val;