1 /***************************************************************************
2  *                                                                         *
3  *   Copyright (C) 2005 Christian Schoenebeck                              *
4  *                                                                         *
5  *   This library is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This library is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this library; if not, write to the Free Software           *
17  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
18  *   MA  02111-1307  USA                                                   *
19  ***************************************************************************/
20 
21 #ifndef __LS_LFOTRIANGLEINTABSMATH_H__
22 #define __LS_LFOTRIANGLEINTABSMATH_H__
23 
24 #include <stdlib.h>
25 #include "LFOTriangleIntMath.h"
26 
27 namespace LinuxSampler {
28 
29     /** @brief Triangle LFO (int math implementation)
30      *
31      * This is a triangle Low Frequency Oscillator which uses pure integer
32      * math (without branches) to synthesize the triangular wave.
33      */
34     template<LFO::range_type_t RANGE>
35     class LFOTriangleIntAbsMath : public LFOTriangleIntMath<RANGE> {
36         public:
37             /**
38              * Constructor
39              *
40              * @param Max - maximum value of the output levels
41              */
LFOTriangleIntAbsMath(float Max)42             LFOTriangleIntAbsMath(float Max) : LFOTriangleIntMath<RANGE>::LFOTriangleIntMath(Max) {
43                 //NOTE: DO NOT add any custom initialization here, since it would break LFOCluster construction !
44             }
45 
46             /**
47              * Calculates exactly one sample point of the LFO wave.
48              *
49              * @returns next LFO level
50              */
render()51             inline float render() {
52                 this->iLevel += this->c;
53                 if (RANGE == LFO::range_unsigned)
54                     return this->normalizer * (float) (abs(this->iLevel));
55                 else /* signed range */
56                     return this->normalizer * (float) (abs(this->iLevel)) + this->offset;
57             }
58     };
59 
60 } // namespace LinuxSampler
61 
62 #endif // __LS_LFOTRIANGLEINTABSMATH_H__
63