Path: blob/master/libs/fluidsynth/src/rvoice/fluid_lfo.h
4396 views
/* FluidSynth - A Software Synthesizer1*2* Copyright (C) 2003 Peter Hanappe and others.3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public License6* as published by the Free Software Foundation; either version 2.1 of7* the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful, but10* WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* You should have received a copy of the GNU Lesser General Public15* License along with this library; if not, write to the Free16* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA17* 02110-1301, USA18*/1920#ifndef _FLUID_LFO_H21#define _FLUID_LFO_H2223#include "fluid_sys.h"2425typedef struct _fluid_lfo_t fluid_lfo_t;2627struct _fluid_lfo_t28{29fluid_real_t val; /* the current value of the LFO */30unsigned int delay; /* the delay of the lfo in samples */31fluid_real_t increment; /* the lfo frequency is converted to a per-buffer increment */32};3334static FLUID_INLINE void35fluid_lfo_reset(fluid_lfo_t *lfo)36{37lfo->val = 0.0f;38}3940// These two cannot be inlined since they're used by event_dispatch41DECLARE_FLUID_RVOICE_FUNCTION(fluid_lfo_set_incr);42DECLARE_FLUID_RVOICE_FUNCTION(fluid_lfo_set_delay);4344static FLUID_INLINE fluid_real_t45fluid_lfo_get_val(fluid_lfo_t *lfo)46{47return lfo->val;48}4950static FLUID_INLINE void51fluid_lfo_calc(fluid_lfo_t *lfo, unsigned int cur_delay)52{53if(cur_delay < lfo->delay)54{55return;56}5758lfo->val += lfo->increment;5960if(lfo->val > (fluid_real_t) 1.0)61{62lfo->increment = -lfo->increment;63lfo->val = (fluid_real_t) 2.0 - lfo->val;64}65else if(lfo->val < (fluid_real_t) -1.0)66{67lfo->increment = -lfo->increment;68lfo->val = (fluid_real_t) -2.0 - lfo->val;69}7071}7273#endif747576