{"", NULL}
};
-Sound::Sound()
+SGSound::SGSound()
: _sample(NULL),
_condition(NULL),
_property(NULL),
_active(false),
_name(""),
- _mode(Sound::ONCE),
+ _mode(SGSound::ONCE),
_prev_value(0),
_dt_play(0.0),
_dt_stop(0.0),
{
}
-Sound::~Sound()
+SGSound::~SGSound()
{
_mgr->get_scheduler()->stopSample(_sample->get_sample());
}
void
-Sound::init(SGPropertyNode *root, SGPropertyNode *node, SoundMgr *sndmgr,
- const string &path)
+SGSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr,
+ const string &path)
{
//
const char *mode_str = node->getStringValue("mode", "");
if ( !strcmp(mode_str, "looped") ) {
- _mode = Sound::LOOPED;
+ _mode = SGSound::LOOPED;
} else if ( !strcmp(mode_str, "in-transit") ) {
- _mode = Sound::IN_TRANSIT;
+ _mode = SGSound::IN_TRANSIT;
} else {
- _mode = Sound::ONCE;
+ _mode = SGSound::ONCE;
if ( strcmp(mode_str, "") )
SG_LOG(SG_GENERAL,SG_INFO, " Unknown sound mode, default to 'once'");
unsigned int i;
float v = 0.0;
vector<SGPropertyNode_ptr> kids = node->getChildren("volume");
- for (i = 0; (i < kids.size()) && (i < Sound::MAXPROP); i++) {
+ for (i = 0; (i < kids.size()) && (i < SGSound::MAXPROP); i++) {
_snd_prop volume = {NULL, NULL, NULL, 1.0, 0.0, 0.0, 0.0, false};
if (strcmp(kids[i]->getStringValue("property"), ""))
//
float p = 0.0;
kids = node->getChildren("pitch");
- for (i = 0; (i < kids.size()) && (i < Sound::MAXPROP); i++) {
+ for (i = 0; (i < kids.size()) && (i < SGSound::MAXPROP); i++) {
_snd_prop pitch = {NULL, NULL, NULL, 1.0, 1.0, 0.0, 0.0, false};
if (strcmp(kids[i]->getStringValue("property", ""), ""))
}
void
-Sound::update (double dt)
+SGSound::update (double dt)
{
double curr_value = 0.0;
(!_condition && _property &&
(
!curr_value ||
- ( (_mode == Sound::IN_TRANSIT) && (curr_value == _prev_value) )
+ ( (_mode == SGSound::IN_TRANSIT) && (curr_value == _prev_value) )
)
)
)
{
- if ((_mode != Sound::IN_TRANSIT) || (_stopping > MAX_TRANSIT_TIME)) {
+ if ((_mode != SGSound::IN_TRANSIT) || (_stopping > MAX_TRANSIT_TIME)) {
if (_sample->is_playing()) {
SG_LOG(SG_GENERAL, SG_INFO, "Stopping audio after " << _dt_play
<< " sec: " << _name );
// If the mode is ONCE and the sound is still playing,
// we have nothing to do anymore.
//
- if (_active && (_mode == Sound::ONCE)) {
+ if (_active && (_mode == SGSound::ONCE)) {
if (!_sample->is_playing()) {
_dt_stop += dt;
//
if (!_active) {
- if (_mode == Sound::ONCE)
+ if (_mode == SGSound::ONCE)
_sample->play(_mgr->get_scheduler(), false);
else
#define MAX_SOUND_SAFETY ( 1.0 / SOUND_SAFETY_MULT )
//
-// SimpleSound
+// SGSimpleSound
//
// constructor
-SimpleSound::SimpleSound( const char *path, const char *file )
+SGSimpleSound::SGSimpleSound( const char *path, const char *file )
: sample(NULL),
pitch_envelope(NULL),
volume_envelope(NULL),
volume_envelope->setStep ( 0, 0.01, 1.0 );
}
-SimpleSound::SimpleSound( unsigned char *buffer, int len )
+SGSimpleSound::SGSimpleSound( unsigned char *buffer, int len )
: pitch(1.0),
volume(1.0)
{
}
// destructor
-SimpleSound::~SimpleSound() {
+SGSimpleSound::~SGSimpleSound() {
delete pitch_envelope;
delete volume_envelope;
delete sample;
}
-void SimpleSound::play( slScheduler *sched, bool looped ) {
+void SGSimpleSound::play( slScheduler *sched, bool looped ) {
// make sure sound isn't already playing
if ( sample->getPlayCount() > 0 ) {
sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
}
-void SimpleSound::stop( slScheduler *sched, bool quick ) {
+void SGSimpleSound::stop( slScheduler *sched, bool quick ) {
sched->stopSample( sample );
}
//
// constructor
-SoundMgr::SoundMgr() {
+SGSoundMgr::SGSoundMgr() {
audio_sched = new slScheduler( 8000 );
if ( audio_sched->notWorking() ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" );
// destructor
-SoundMgr::~SoundMgr() {
+SGSoundMgr::~SGSoundMgr() {
//
// Remove the samples from the sample manager.
sound_map_iterator sound_current = sounds.begin();
sound_map_iterator sound_end = sounds.end();
for ( ; sound_current != sound_end; ++sound_current ) {
- SimpleSound *s = sound_current->second;
+ SGSimpleSound *s = sound_current->second;
audio_sched->stopSample(s->get_sample());
delete s->get_sample();
// initialize the sound manager
-void SoundMgr::init() {
+void SGSoundMgr::init() {
safety = MAX_SOUND_SAFETY;
// audio_mixer -> setMasterVolume ( 80 ) ; /* 80% of max volume. */
sound_map_iterator sound_current = sounds.begin();
sound_map_iterator sound_end = sounds.end();
for ( ; sound_current != sound_end; ++sound_current ) {
- SimpleSound *s = sound_current->second;
+ SGSimpleSound *s = sound_current->second;
audio_sched->stopSample(s->get_sample());
delete s->get_sample();
}
-void SoundMgr::bind ()
+void SGSoundMgr::bind ()
{
// no properties yet
}
-void SoundMgr::unbind ()
+void SGSoundMgr::unbind ()
{
// no properties yet
}
// run the audio scheduler
-void SoundMgr::update( double dt ) {
+void SGSoundMgr::update( double dt ) {
if ( dt > safety ) {
safety = dt;
} else {
void
-SoundMgr::pause ()
+SGSoundMgr::pause ()
{
audio_sched->pauseSample(0, 0);
}
void
-SoundMgr::resume ()
+SGSoundMgr::resume ()
{
audio_sched->resumeSample(0, 0);
}
// add a sound effect, return true if successful
-bool SoundMgr::add( SimpleSound *sound, const string& refname ) {
+bool SGSoundMgr::add( SGSimpleSound *sound, const string& refname ) {
sound_map_iterator sound_it = sounds.find( refname );
if ( sound_it != sounds.end() ) {
// add a sound from a file, return the sample if successful, else return NULL
-SimpleSound *SoundMgr::add( const string &refname,
+SGSimpleSound *SGSoundMgr::add( const string &refname,
const char *path, const char *file ) {
- SimpleSound *sound;
+ SGSimpleSound *sound;
SGPath slfile( path );
if ( file )
sample_map_iterator it = samples.find(slfile.str());
if (it == samples.end()) {
- sound = new SimpleSound(slfile.c_str());
+ sound = new SGSimpleSound(slfile.c_str());
sounds[refname] = sound;
sample_ref *sr = new sample_ref;
sr->n++;
sound =
- new SimpleSound(sr->sample->getBuffer(), sr->sample->getLength());
+ new SGSimpleSound(sr->sample->getBuffer(), sr->sample->getLength());
sounds[refname] = sound;
}
// remove a sound effect, return true if successful
-bool SoundMgr::remove( const string &refname ) {
+bool SGSoundMgr::remove( const string &refname ) {
sound_map_iterator it = sounds.find( refname );
if ( it != sounds.end() ) {
// first stop the sound from playing (so we don't bomb the
// audio scheduler)
- SimpleSound *sample = it->second;
+ SGSimpleSound *sample = it->second;
// cout << "Playing " << sample->get_sample()->getPlayCount()
// << " instances!" << endl;
// return true of the specified sound exists in the sound manager system
-bool SoundMgr::exists( const string &refname ) {
+bool SGSoundMgr::exists( const string &refname ) {
sound_map_iterator it = sounds.find( refname );
if ( it != sounds.end() ) {
return true;
}
-// return a pointer to the SimpleSound if the specified sound exists
+// return a pointer to the SGSimpleSound if the specified sound exists
// in the sound manager system, otherwise return NULL
-SimpleSound *SoundMgr::find( const string &refname ) {
+SGSimpleSound *SGSoundMgr::find( const string &refname ) {
sound_map_iterator it = sounds.find( refname );
if ( it != sounds.end() ) {
return it->second;
// tell the scheduler to play the indexed sample in a continuous
// loop
-bool SoundMgr::play_looped( const string &refname ) {
- SimpleSound *sample;
+bool SGSoundMgr::play_looped( const string &refname ) {
+ SGSimpleSound *sample;
if ((sample = find( refname )) == NULL)
return false;
// tell the scheduler to play the indexed sample once
-bool SoundMgr::play_once( const string& refname ) {
- SimpleSound *sample;
+bool SGSoundMgr::play_once( const string& refname ) {
+ SGSimpleSound *sample;
if ((sample = find( refname )) == NULL)
return false;
// return true of the specified sound is currently being played
-bool SoundMgr::is_playing( const string& refname ) {
- SimpleSound *sample;
+bool SGSoundMgr::is_playing( const string& refname ) {
+ SGSimpleSound *sample;
if ((sample = find( refname )) == NULL)
return false;
// immediate stop playing the sound
-bool SoundMgr::stop( const string& refname ) {
- SimpleSound *sample;
+bool SGSoundMgr::stop( const string& refname ) {
+ SGSimpleSound *sample;
if ((sample = find( refname )) == NULL)
return false;
// manages everything we need to know for an individual sound sample
-class SimpleSound {
+class SGSimpleSound {
private:
public:
- SimpleSound( const char *path, const char *file = NULL );
- SimpleSound( unsigned char *buffer, int len );
- ~SimpleSound();
+ SGSimpleSound( const char *path, const char *file = NULL );
+ SGSimpleSound( unsigned char *buffer, int len );
+ ~SGSimpleSound();
void play( slScheduler *sched, bool looped );
void stop( slScheduler *sched, bool quick = true );
typedef sample_map::iterator sample_map_iterator;
typedef sample_map::const_iterator const_sample_map_iterator;
-
-typedef map < string, SimpleSound * > sound_map;
+typedef map < string, SGSimpleSound * > sound_map;
typedef sound_map::iterator sound_map_iterator;
typedef sound_map::const_iterator const_sound_map_iterator;
-class SoundMgr
+class SGSoundMgr
{
slScheduler *audio_sched;
public:
- SoundMgr();
- ~SoundMgr();
+ SGSoundMgr();
+ ~SGSoundMgr();
/**
inline void reinit() { init(); }
// add a sound effect, return true if successful
- bool add( SimpleSound *sound, const string& refname);
+ bool add( SGSimpleSound *sound, const string& refname);
// add a sound file, return the sample if successful, else return NULL
- SimpleSound *add( const string& refname,
+ SGSimpleSound *add( const string& refname,
const char *path, const char *file = NULL );
// remove a sound effect, return true if successful
// return true of the specified sound exists in the sound manager system
bool exists( const string& refname );
- // return a pointer to the SimpleSound if the specified sound
+ // return a pointer to the SGSimpleSound if the specified sound
// exists in the sound manager system, otherwise return NULL
- SimpleSound *find( const string& refname );
+ SGSimpleSound *find( const string& refname );
// tell the scheduler to play the indexed sample in a continuous
// loop