]> git.mxchange.org Git - flightgear.git/blob - src/Sound/fg_sound.hxx
d8f71357d7de3823f23c436d302ac2f7d5ce4009
[flightgear.git] / src / Sound / fg_sound.hxx
1 // fg_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 __FGSOUND_HXX
24 #define __FGSOUND_HXX 1
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <simgear/compiler.h>
31 #include <Main/fgfs.hxx>
32 #include <Main/globals.hxx>
33
34 #include "soundmgr.hxx"
35
36 static const double MAX_TRANSIT_TIME = 0.1;     // 100 ms.
37
38
39 /**
40  * Class for handling one sound event.
41  *
42  */
43 class FGSound
44 {
45
46 public:
47
48   FGSound();
49   virtual ~FGSound();
50
51   virtual void init (SGPropertyNode *);
52   virtual void bind ();
53   virtual void unbind ();
54   virtual void update (double dt);
55
56   void stop();
57
58 protected:
59
60   enum { MAXPROP=5 };
61   enum { ONCE=0, LOOPED, IN_TRANSIT };
62   enum { LEVEL=0, INVERTED, FLIPFLOP };
63
64   // Sound properties
65   typedef struct {
66         SGPropertyNode * prop;
67         double (*fn)(double);
68         double *intern;
69         double factor;
70         double offset;
71         double min;
72         double max;
73         bool subtract;
74   } _snd_prop;
75
76 private:
77
78   FGSoundMgr * _mgr;
79   FGSimpleSound * _sample;
80
81   FGCondition * _condition;
82   SGPropertyNode * _property;
83
84   bool _active;
85   string _name;
86   int _mode;
87   double _prev_value;
88   double _dt_play;
89   double _dt_stop;
90   double _stopping;     // time after the sound should have stopped.
91                         // This is usefull for lost packets in in-trasit mode.
92
93   vector<_snd_prop> _volume;
94   vector<_snd_prop> _pitch;
95
96 };
97
98 #endif