]> git.mxchange.org Git - flightgear.git/blob - src/Sound/fg_sound.hxx
Fix a bug in transit sound termination and adjust the minimum time we
[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;     // 10 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 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   FGSoundMgr * _mgr;
77   FGSimpleSound * _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