1 |
/*************************************************************************** |
2 |
* * |
3 |
* Copyright (C) 2006 Andreas Persson * |
4 |
* * |
5 |
* This program 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 program 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 program; if not, write to the Free Software * |
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * |
18 |
* MA 02110-1301 USA * |
19 |
***************************************************************************/ |
20 |
|
21 |
#ifndef __LS_GIG_SMOOTHVOLUME_H__ |
22 |
#define __LS_GIG_SMOOTHVOLUME_H__ |
23 |
|
24 |
namespace LinuxSampler { namespace gig { |
25 |
|
26 |
/** |
27 |
* Filter that smoothens out sudden changes in volume level. |
28 |
*/ |
29 |
class SmoothVolume { |
30 |
public: |
31 |
|
32 |
/** |
33 |
* Initializes the smooth volume. |
34 |
* |
35 |
* @param volume - initial volume value |
36 |
* @param sampleRate - rate at which the render function |
37 |
* will be called |
38 |
*/ |
39 |
void trigger(float volume, float sampleRate); |
40 |
|
41 |
/** |
42 |
* Sets a new volume. The render function will return |
43 |
* values gradually approaching this value. |
44 |
* |
45 |
* @param newVolume - new volume value |
46 |
*/ |
47 |
void update(float newVolume) { |
48 |
goal = newVolume; |
49 |
moving = true; |
50 |
} |
51 |
|
52 |
/** |
53 |
* Calculates exactly one sample point of the volume |
54 |
* curve. |
55 |
* |
56 |
* @returns next volume level |
57 |
*/ |
58 |
float render() { return moving ? process() : volume; } |
59 |
|
60 |
private: |
61 |
bool moving; |
62 |
float goal; |
63 |
float volume; |
64 |
float coeff; |
65 |
float decay; |
66 |
float a1; |
67 |
float b0; |
68 |
float process(); |
69 |
}; |
70 |
|
71 |
}}; |
72 |
#endif |