1 // fgfx.cxx -- Sound effect management class implementation
3 // Started by David Megginson, October 2001
4 // (Reuses some code from main.cxx, probably by Curtis Olson)
6 // Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 // FIXME: remove direct dependencies
27 #include <Controls/controls.hxx>
28 #include <FDM/flight.hxx>
29 #include <Main/fg_props.hxx>
33 : _is_cranking(false),
49 // FIXME: is this right, or does the
50 // sound manager assume pointer ownership?
66 FGSoundMgr * mgr = globals->get_soundmgr();
69 // Create and add the engine sound
72 new FGSimpleSound(fgGetString("/sim/sounds/engine", "Sounds/wasp.wav"));
73 mgr->add(_engine, "engine loop");
74 mgr->play_looped("engine loop");
76 SG_LOG( SG_GENERAL, SG_INFO,
77 "Rate = " << _engine->get_sample()->getRate()
78 << " Bps = " << _engine->get_sample()->getBps()
79 << " Stereo = " << _engine->get_sample()->getStereo() );
83 // Create and add the cranking sound.
86 new FGSimpleSound(fgGetString("/sim/sounds/cranking",
87 "Sounds/cranking.wav"));
88 mgr->add(_crank, "crank");
89 _crank->set_pitch(1.5);
90 _crank->set_volume(0.25);
94 // Create and add the wind noise.
97 new FGSimpleSound(fgGetString("/sim/sounds/wind", "Sounds/wind.wav"));
98 mgr->add(_wind, "wind");
99 mgr->play_looped("wind");
103 // Create and add the stall noise.
105 _stall = new FGSimpleSound(fgGetString("/sim/sounds/stall",
106 "Sounds/stall.wav"));
107 mgr->add(_stall, "stall");
110 // Create and add the rumble noise.
112 _rumble = new FGSimpleSound(fgGetString("/sim/sounds/rumble",
113 "Sounds/rumble.wav"));
114 mgr->add(_rumble, "rumble");
117 // Create and add the squeal noise.
119 _squeal = new FGSimpleSound(fgGetString("/sim/sounds/squeal",
120 "Sounds/squeal.wav"));
121 mgr->add(_squeal, "squeal");
124 // Create and add the click noise.
125 _click = new FGSimpleSound(fgGetString("/sim/sounds/click",
126 "Sounds/click.wav"));
127 mgr->add(_click, "click");
143 FGSoundMgr * mgr = globals->get_soundmgr();
146 ////////////////////////////////////////////////////////////////////
147 // Update the engine sound.
148 ////////////////////////////////////////////////////////////////////
150 if (fgGetBool("/engines/engine[0]/running")) { // FIXME
151 // pitch corresponds to rpm
152 // volume corresponds to manifold pressure
155 if (cur_fdm_state->get_engine(0) != NULL)
156 rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0;
160 double pitch = 0.3 + rpm_factor * 3.0;
162 // don't run at absurdly slow rates -- not realistic
163 // and sounds bad to boot. :-)
170 if (cur_fdm_state->get_engine(0) != NULL)
171 mp_factor = cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 100;
175 double volume = 0.15 + mp_factor / 2.0;
182 _engine->set_pitch( pitch );
183 _engine->set_volume( volume );
185 _engine->set_pitch(0.0);
186 _engine->set_volume(0.0);
190 ////////////////////////////////////////////////////////////////////
191 // Update the cranking sound.
192 ////////////////////////////////////////////////////////////////////
194 if (fgGetBool("/engines/engine[0]/cranking")) { // FIXME
196 globals->get_soundmgr()->play_looped("crank");
201 globals->get_soundmgr()->stop("crank");
202 _is_cranking = false;
207 ////////////////////////////////////////////////////////////////////
208 // Update the wind noise.
209 ////////////////////////////////////////////////////////////////////
211 float rel_wind = cur_fdm_state->get_V_rel_wind();
212 float volume = rel_wind/300.0; // FIXME!!!
213 _wind->set_volume(volume);