]> git.mxchange.org Git - simgear.git/blob - simgear/sound/sound.hxx
cd0c96ed9ef6630ee8e29f72648e8ef8fca9868e
[simgear.git] / simgear / sound / sound.hxx
1 // sound.hxx -- Sound class implementation
2 //
3 // Started by Erik Hofman, February 2002
4 //
5 // Copyright (C) 2002  Erik Hofman - erik@ehofman.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23 #ifndef _SG_SOUND_HXX
24 #define _SG_SOUND_HXX 1
25
26 #ifndef __cplusplus
27 # error This library requires C++
28 #endif
29
30 #include <simgear/compiler.h>
31 #include <simgear/props/condition.hxx>
32
33 #include "soundmgr.hxx"
34
35 static const double MAX_TRANSIT_TIME = 0.1;     // 100 ms.
36
37
38 /**
39  * Class for handling one sound event.
40  *
41  */
42 class Sound
43 {
44
45 public:
46
47   Sound();
48   virtual ~Sound();
49
50   virtual void init (SGPropertyNode *, SGPropertyNode *, SoundMgr *,
51                      const string &);
52   virtual void update (double dt);
53
54   void stop();
55
56 protected:
57
58   enum { MAXPROP=5 };
59   enum { ONCE=0, LOOPED, IN_TRANSIT };
60   enum { LEVEL=0, INVERTED, FLIPFLOP };
61
62   // Sound properties
63   typedef struct {
64         SGPropertyNode * prop;
65         double (*fn)(double);
66         double *intern;
67         double factor;
68         double offset;
69         double min;
70         double max;
71         bool subtract;
72   } _snd_prop;
73
74 private:
75
76   SoundMgr * _mgr;
77   SimpleSound * _sample;
78
79   FGCondition * _condition;
80   SGPropertyNode * _property;
81
82   bool _active;
83   string _name;
84   int _mode;
85   double _prev_value;
86   double _dt_play;
87   double _dt_stop;
88   double _stopping;     // time after the sound should have stopped.
89                         // This is usefull for lost packets in in-trasit mode.
90
91   vector<_snd_prop> _volume;
92   vector<_snd_prop> _pitch;
93
94 };
95
96 #endif // _SG_SOUND_HXX