1 // sound.hxx -- Sound class implementation
3 // Started by Erik Hofman, February 2002
5 // Copyright (C) 2002 Erik Hofman - erik@ehofman.com
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.
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.
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.
25 * Provides a class to manage a single sound event including things
26 * like looping, volume and pitch changes.
30 #define _SG_SOUND_HXX 1
33 # error This library requires C++
36 #include <simgear/compiler.h>
37 #include <simgear/props/condition.hxx>
39 #include "sample_openal.hxx"
40 #include "soundmgr_openal.hxx"
42 static const double MAX_TRANSIT_TIME = 0.1; // 100 ms.
46 * Class for handling one sound event.
48 * This class handles everything for a particular sound event, by
49 * scanning an a pre-loaded property tree structure for sound
50 * settings, setting up its internal states, and managing sound
51 * playback whenever such an event happens.
59 virtual ~SGXmlSound();
62 * Initialize the sound event.
64 * Prior to initialization of the sound event the propgrams property root
65 * has to be defined, the sound configuration XML tree has to be loaded
66 * and a sound manager class has to be defined.
68 * A sound configuration file would look like this:
71 * <name/> Define the name of the event. For refference only.
73 * looped: play this sound looped.
74 * in-transit: play looped while the event is happening.
75 * once: play this sound once.
76 * <path/> The relative path to the audio file.
77 * <property/> Take action if this property becomes true.
78 * <condition/> Take action if this condition becomes true.
79 * <volume> or <pitch> Define volume or pitch settings.
80 * <property/> Take the value of this property as a refference for the
83 * dt_start: the time elapsed since this sound is playing.
84 * dt_stop: the time elapsed since this sound has stopped.
85 * <offset/> Add this value to the result.
86 * <factor/> Multiply the result by this factor.
87 * <min/> Make sure the value is never less than this value.
88 * <max/> Make sure the value is never larger than this value.
89 * </volume> or </pitch>
96 * @param root The root node of the programs property tree.
97 * @param child A pointer to the location of the current event as defined
98 * in the configuration file.
99 * @param sndmgr A pointer to a pre-initialized sound manager class.
100 * @param path The path where the audio files remain.
102 virtual void init (SGPropertyNode *, SGPropertyNode *, SGSoundMgr *,
106 * Check wheter an event has happened and if action has to be taken.
108 virtual void update (double dt);
111 * Stop taking action on the pre-defined events.
118 enum { ONCE=0, LOOPED, IN_TRANSIT };
119 enum { LEVEL=0, INVERTED, FLIPFLOP };
121 // SGXmlSound properties
123 SGPropertyNode * prop;
124 double (*fn)(double);
136 SGSoundSample * _sample;
138 SGCondition * _condition;
139 SGPropertyNode * _property;
147 double _stopping; // time after the sound should have stopped.
148 // This is usefull for lost packets in in-trasit mode.
150 vector<_snd_prop> _volume;
151 vector<_snd_prop> _pitch;
155 #endif // _SG_SOUND_HXX