#include <simgear/sound/soundmgr_openal.hxx>
#include <math.h>
#include <string>
-#include <memory>
using std::string;
_rollSuspended = false;
if ( !_sgr ) {
- SGSoundMgr *smgr;
- smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("atc", true);
_sgr->tie_to_listener();
}
#ifdef ENABLE_AUDIO_SUPPORT
voice = (voiceOK && fgGetBool("/sim/sound/voice"));
if(voice) {
- string buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), voice);
+ sizte_t len;
+ void* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), voice, &len);
if(voice && (volume > 0.05)) {
- std::auto_ptr<unsigned char> ptr( (unsigned char*)buf.c_str() );
- SGSoundSample* simple =
- new SGSoundSample(ptr, buf.length(), 8000 );
- // TODO - at the moment the volume can't be changed
- // after the transmission has started.
+ SGSoundSample* simple = new SGSoundSample(buf, len, 8000 );
simple->set_volume(volume);
_sgr->add(simple, refname);
_sgr->play(refname, repeating);
#include "ATC.hxx"
#include <iostream>
-#include <memory>
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/structure/exception.hxx>
_counter(0.0),
_max_count(5.0)
{
- SGSoundMgr *smgr;
- smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("atc", true);
}
#ifdef ENABLE_AUDIO_SUPPORT
_voice = (_voiceOK && fgGetBool("/sim/sound/voice"));
if(_voice) {
- string buf = _vPtr->WriteMessage((char*)msg.c_str(), _voice);
- if(_voice && (volume > 0.05)) {
+ size_t len;
+ void* buf = _vPtr->WriteMessage((char*)msg.c_str(), &len);
+ if(buf && (volume > 0.05)) {
NoRender(refname);
try {
// >>> Beware: must pass a (new) object to the (add) method,
// >>> because the (remove) method is going to do a (delete)
// >>> whether that's what you want or not.
- std::auto_ptr<unsigned char> ptr( (unsigned char*)buf.c_str() );
- SGSoundSample *simple =
- new SGSoundSample(ptr, buf.length(), 8000);
- // TODO - at the moment the volume can't be changed
- // after the transmission has started.
+ SGSoundSample *simple = new SGSoundSample(&buf, len, 8000);
simple->set_volume(volume);
_sgr->add(simple, refname);
_sgr->play(refname, repeating);
string full_path = path.str();
int format, freq;
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
void *data;
if (!smgr->load(full_path, &data, &format, &rawDataSize, &freq))
return false;
// Given a desired message, return a string containing the
// sound-sample data
-string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
+void* FGATCVoice::WriteMessage(const char* message, size_t* len) {
// What should we do here?
// First - parse the message into a list of tokens.
// Check for no tokens found else slScheduler can be crashed
if(!word) {
- dataOK = false;
- return "";
+ *len = 0;
+ return NULL;
}
boost::shared_array<char> tmpbuf(new char[cumLength]);
unsigned int bufpos = 0;
SG_LOG(SG_ATC, SG_ALERT, "Offset + length: " << wdptr[i].offset + wdptr[i].length
<< " exceeds rawdata size: " << rawDataSize << endl);
- dataOK = false;
- return "";
+ *len = 0;
+ return NULL;
}
memcpy(tmpbuf.get() + bufpos, rawSoundData + wdptr[i].offset, wdptr[i].length);
bufpos += wdptr[i].length;
unsigned int offsetIn = (int)(cumLength * sg_random());
if(offsetIn > cumLength) offsetIn = cumLength;
- string front(tmpbuf.get(), offsetIn);
- string back(tmpbuf.get() + offsetIn, cumLength - offsetIn);
+ void *data = malloc(cumLength);
+ memcpy(data, tmpbuf.get(), cumLength);
+ *len = cumLength;
+ // string front(tmpbuf.get(), offsetIn);
+ // string back(tmpbuf.get() + offsetIn, cumLength - offsetIn);
- dataOK = true;
- return back + front;
+ return data;
}
bool LoadVoice(const std::string& voice);
// Given a desired message, return a pointer to the data buffer and write the buffer length into len.
- // Sets dataOK = true if the returned buffer is valid.
- std::string WriteMessage(const char* message, bool& dataOK);
+ // Sets len to something other than 0 if the returned buffer is valid.
+ void* WriteMessage(const char* message, size_t *len);
private:
snd_lightning = new SGSoundSample(globals->get_fg_root().c_str(), "Sounds/thunder.wav");
snd_lightning->set_max_dist(7000.0f);
snd_lightning->set_reference_dist(3000.0f);
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
SGSampleGroup *sgr = smgr->find("weather", true);
sgr->add( snd_lightning, "thunder" );
sgEnviro.set_sampleGroup( sgr );
_ident_node = node->getChild("ident", 0, true);
_ident_audible_node = node->getChild("ident-audible", 0, true);
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
void FGKR_87::init () {
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
morse.init();
if (serviceable->getType() == simgear::props::NONE)
serviceable->setBoolValue( true );
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
{
#define STDPAUSE 0.75 // [SPEC] 6.4.4: "the standard 0.75 second delay"
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
void
FGNavRadio::init ()
{
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
try {
static FGSampleQueue *queue = 0;
if ( !queue ) {
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
queue = new FGSampleQueue(smgr, "queue");
queue->tie_to_listener();
}
globals->get_event_mgr()->init();
globals->get_event_mgr()->setRealtimeProperty(fgGetNode("/sim/time/delta-realtime-sec", true));
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the sound manager subsystem.
+ ////////////////////////////////////////////////////////////////////
+
+ globals->get_soundmgr()->bind();
+ globals->get_soundmgr()->init();
+
////////////////////////////////////////////////////////////////////
// Initialize the property interpolator subsystem. Put into the INIT
// group because the "nasal" subsystem may need it at GENERAL take-down.
frozen = f;
// Stop sound on a pause
- SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
if ( smgr != NULL ) {
if ( f ) {
smgr->suspend();
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#include <simgear/scene/material/matlib.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/event_mgr.hxx>
+#include <simgear/sound/soundmgr_openal.hxx>
#include <Aircraft/controls.hxx>
#include <Airports/runways.hxx>
renderer( new FGRenderer ),
subsystem_mgr( new SGSubsystemMgr ),
event_mgr( new SGEventMgr ),
+ soundmgr( new SGSoundMgr ),
sim_time_sec( 0.0 ),
fg_root( "" ),
warp( 0 ),
delete channellist;
delete airwaynet;
delete multiplayer_mgr;
+
+ soundmgr->unbind();
+ delete soundmgr;
}
subsystem_mgr->add(name, subsystem, type, min_time_sec);
}
+SGSoundMgr *
+FGGlobals::get_soundmgr () const
+{
+ return soundmgr;
+}
SGEventMgr *
FGGlobals::get_event_mgr () const
class SGEventMgr;
class SGSubsystemMgr;
class SGSubsystem;
+class SGSoundMgr;
class FGAIMgr;
class FGATCMgr;
FGRenderer *renderer;
SGSubsystemMgr *subsystem_mgr;
SGEventMgr *event_mgr;
+ SGSoundMgr *soundmgr;
// Number of milliseconds elapsed since the start of the program.
double sim_time_sec;
virtual SGEventMgr *get_event_mgr () const;
+ virtual SGSoundMgr *get_soundmgr () const;
+
inline double get_sim_time_sec () const { return sim_time_sec; }
inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
inline void set_sim_time_sec (double t) { sim_time_sec = t; }
// is processing the scenery (doubled the frame-rate for me) -EMH-
////////////////////////////////////////////////////////////////////
#ifdef ENABLE_AUDIO_SUPPORT
- static SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ static SGSoundMgr *smgr = globals->get_soundmgr();
smgr->update_late(delta_time_sec);
#endif
} else if ( idle_state == 5 ) {
idle_state++;
-#ifdef ENABLE_AUDIO_SUPPORT
- ////////////////////////////////////////////////////////////////////
- // Add the Sound Manager before any other subsystem that uses it.
- // This makes sure the SoundMgr is available at construction time.
- ////////////////////////////////////////////////////////////////////
- globals->add_subsystem("soundmgr", new SGSoundMgr);
-#endif
////////////////////////////////////////////////////////////////////
// Initialize the 3D aircraft model subsystem (has a dependency on
config_list(fgGetNode("/sim", true)->getChildren("view")),
current(0)
{
- smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ smgr = globals->get_soundmgr();
}
// Destructor
_speed_e(0),
_speed_d(0)
{
- SGSoundMgr *smgr;
- smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+ SGSoundMgr *smgr = globals->get_soundmgr();
_fx = new FGFX(smgr, "fx");
_fx->init();
}
// $Id$
-#include <memory>
+#include <stdlib.h>
#include "beacon.hxx"
// allocate and initialize sound samples
bool FGBeacon::init() {
- int i;
- int len;
unsigned char *ptr;
+ size_t i, len;
- std::auto_ptr<unsigned char>inner_buf( new unsigned char[ INNER_SIZE ] );
- std::auto_ptr<unsigned char>middle_buf( new unsigned char[ MIDDLE_SIZE ] );
- std::auto_ptr<unsigned char>outer_buf( new unsigned char[ OUTER_SIZE ] );
+ const unsigned char* inner_buf = (const unsigned char*)malloc( INNER_SIZE );
+ const unsigned char* middle_buf = (const unsigned char*)malloc(MIDDLE_SIZE);
+ const unsigned char* outer_buf = (const unsigned char*)malloc( OUTER_SIZE );
// Make inner marker beacon sound
len= (int)(INNER_DIT_LEN / 2.0 );
make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
TRANSITION_BYTES );
- ptr = inner_buf.get();
+ ptr = (unsigned char*)inner_buf;
for ( i = 0; i < 6; ++i ) {
memcpy( ptr, inner_dit, INNER_DIT_LEN );
ptr += INNER_DIT_LEN;
}
try {
- inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND );
+ inner = new SGSoundSample( &inner_buf, INNER_SIZE, BYTES_PER_SECOND );
inner->set_reference_dist( 10.0 );
inner->set_max_dist( 20.0 );
make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
TRANSITION_BYTES );
- ptr = middle_buf.get();
+ ptr = (unsigned char*)middle_buf;
memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
ptr += MIDDLE_DIT_LEN;
memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
- middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND );
+ middle = new SGSoundSample( &middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND);
middle->set_reference_dist( 10.0 );
middle->set_max_dist( 20.0 );
make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
TRANSITION_BYTES );
- ptr = outer_buf.get();
+ ptr = (unsigned char*)outer_buf;
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
ptr += OUTER_DAH_LEN;
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
- outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND );
+ outer = new SGSoundSample( &outer_buf, OUTER_SIZE, BYTES_PER_SECOND );
outer->set_reference_dist( 10.0 );
outer->set_max_dist( 20.0 );
} catch ( sg_io_exception &e ) {
// $Id$
-#include <memory>
-
#include <simgear/constants.h>
#include "morse.hxx"
length += 2 * SPACE_SIZE;
// 2. Allocate space for the message
- std::auto_ptr<unsigned char>buffer( new unsigned char[length] );
+ const unsigned char* buffer = (const unsigned char *)malloc(length);
// 3. Assemble the message;
- unsigned char *buf_ptr = buffer.get();
+ unsigned char *buf_ptr = (unsigned char*)buffer;
for ( i = 0; i < (int)id.length(); ++i ) {
if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) {
buf_ptr += SPACE_SIZE;
// 4. create the simple sound and return
- SGSoundSample *sample = new SGSoundSample( buffer, length,
+ SGSoundSample *sample = new SGSoundSample( &buffer, length,
BYTES_PER_SECOND );
sample->set_reference_dist( 10.0 );