1
0
Fork 0

Don't make the SoundManager a memebr of the subsystem manager; It needs to be initialized very early and destroyed as late as possible. That doesn't work as a subsystem meber onless some sort of priority scheme gets implemented. Get rid of auto_ptr which doesn work for the samples either.

This commit is contained in:
ehofman 2009-10-24 08:31:37 +00:00 committed by Tim Moore
parent 9c8d6ee663
commit f9445874a0
20 changed files with 71 additions and 69 deletions

View file

@ -24,7 +24,6 @@
#include <simgear/sound/soundmgr_openal.hxx>
#include <math.h>
#include <string>
#include <memory>
using std::string;
@ -52,8 +51,7 @@ FGAIPlane::FGAIPlane() {
_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();
}
@ -199,13 +197,10 @@ void FGAIPlane::Render(const string& refname, const float volume, bool repeating
#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);

View file

@ -25,7 +25,6 @@
#include "ATC.hxx"
#include <iostream>
#include <memory>
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/structure/exception.hxx>
@ -57,8 +56,7 @@ FGATC::FGATC() :
_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);
}
@ -231,18 +229,15 @@ void FGATC::Render(string& msg, const float volume,
#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);

View file

@ -72,7 +72,7 @@ bool FGATCVoice::LoadVoice(const string& voice) {
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;
@ -134,7 +134,7 @@ typedef tokenList_type::iterator tokenList_iterator;
// 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.
@ -185,8 +185,8 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
// 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;
@ -202,8 +202,8 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
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;
@ -213,9 +213,11 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
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;
}

View file

@ -49,8 +49,8 @@ public:
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:

View file

@ -68,7 +68,7 @@ void FGClouds::init(void) {
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 );

View file

@ -102,7 +102,7 @@ ADF::init ()
_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();

View file

@ -117,7 +117,7 @@ FGKR_87::~FGKR_87() {
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();

View file

@ -117,7 +117,7 @@ FGMarkerBeacon::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();

View file

@ -2200,7 +2200,7 @@ MK_VIII::VoicePlayer::init ()
{
#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();

View file

@ -183,7 +183,7 @@ FGNavRadio::~FGNavRadio()
void
FGNavRadio::init ()
{
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();

View file

@ -1259,7 +1259,7 @@ do_play_audio_sample (const SGPropertyNode * arg)
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();
}

View file

@ -1448,6 +1448,13 @@ bool fgInitSubsystems() {
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.

View file

@ -222,7 +222,7 @@ setFreeze (bool f)
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();

View file

@ -15,8 +15,8 @@
// 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$
@ -32,6 +32,7 @@
#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>
@ -72,6 +73,7 @@ FGGlobals::FGGlobals() :
renderer( new FGRenderer ),
subsystem_mgr( new SGSubsystemMgr ),
event_mgr( new SGEventMgr ),
soundmgr( new SGSoundMgr ),
sim_time_sec( 0.0 ),
fg_root( "" ),
warp( 0 ),
@ -158,6 +160,9 @@ FGGlobals::~FGGlobals()
delete channellist;
delete airwaynet;
delete multiplayer_mgr;
soundmgr->unbind();
delete soundmgr;
}
@ -259,6 +264,11 @@ FGGlobals::add_subsystem (const char * name,
subsystem_mgr->add(name, subsystem, type, min_time_sec);
}
SGSoundMgr *
FGGlobals::get_soundmgr () const
{
return soundmgr;
}
SGEventMgr *
FGGlobals::get_event_mgr () const

View file

@ -52,6 +52,7 @@ class SGTime;
class SGEventMgr;
class SGSubsystemMgr;
class SGSubsystem;
class SGSoundMgr;
class FGAIMgr;
class FGATCMgr;
@ -93,6 +94,7 @@ private:
FGRenderer *renderer;
SGSubsystemMgr *subsystem_mgr;
SGEventMgr *event_mgr;
SGSoundMgr *soundmgr;
// Number of milliseconds elapsed since the start of the program.
double sim_time_sec;
@ -198,6 +200,8 @@ public:
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; }

View file

@ -482,7 +482,7 @@ static void fgMainLoop( void ) {
// 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
@ -636,13 +636,6 @@ static void fgIdleFunction ( void ) {
} 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

View file

@ -43,7 +43,7 @@ FGViewMgr::FGViewMgr( void ) :
config_list(fgGetNode("/sim", true)->getChildren("view")),
current(0)
{
smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
smgr = globals->get_soundmgr();
}
// Destructor

View file

@ -48,8 +48,7 @@ FGAircraftModel::FGAircraftModel ()
_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();
}

View file

@ -21,7 +21,7 @@
// $Id$
#include <memory>
#include <stdlib.h>
#include "beacon.hxx"
@ -39,13 +39,12 @@ FGBeacon::~FGBeacon() {
// 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 );
@ -53,14 +52,14 @@ bool FGBeacon::init() {
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 );
@ -75,12 +74,12 @@ bool FGBeacon::init() {
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 );
@ -90,12 +89,12 @@ bool FGBeacon::init() {
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 ) {

View file

@ -21,8 +21,6 @@
// $Id$
#include <memory>
#include <simgear/constants.h>
#include "morse.hxx"
@ -221,10 +219,10 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) {
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' ) {
@ -263,7 +261,7 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) {
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 );