Patches from Erik.
This commit is contained in:
parent
914b5636e4
commit
c5f43ca688
3 changed files with 75 additions and 55 deletions
|
@ -279,7 +279,7 @@ FGSound::update (int dt)
|
||||||
//
|
//
|
||||||
// If the state changes to false, stop playing.
|
// If the state changes to false, stop playing.
|
||||||
//
|
//
|
||||||
if (check == 0) {
|
if (!check) {
|
||||||
_active = false;
|
_active = false;
|
||||||
if (mgr->is_playing(_name)) {
|
if (mgr->is_playing(_name)) {
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "Stopping sound: " << _name);
|
SG_LOG(SG_GENERAL, SG_INFO, "Stopping sound: " << _name);
|
||||||
|
@ -298,7 +298,7 @@ FGSound::update (int dt)
|
||||||
} else { // FLIPFLOP, RAISE, FALL
|
} else { // FLIPFLOP, RAISE, FALL
|
||||||
|
|
||||||
bool check = (int)(_offset + _property->getFloatValue() * _factor);
|
bool check = (int)(_offset + _property->getFloatValue() * _factor);
|
||||||
if ((bool)check == _active)
|
if (check == _active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -390,9 +390,9 @@ FGSound::update (int dt)
|
||||||
_active = !_active;
|
_active = !_active;
|
||||||
|
|
||||||
if (_mode == FGSound::ONCE)
|
if (_mode == FGSound::ONCE)
|
||||||
mgr->play_once(_name);
|
_sample->play(mgr->get_scheduler(), false);
|
||||||
else
|
else
|
||||||
mgr->play_looped(_name);
|
_sample->play(mgr->get_scheduler(), true);
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "Starting audio playback for: " << _name);
|
SG_LOG(SG_GENERAL, SG_INFO, "Starting audio playback for: " << _name);
|
||||||
SG_LOG(SG_GENERAL, SG_BULK,
|
SG_LOG(SG_GENERAL, SG_BULK,
|
||||||
|
|
|
@ -34,6 +34,10 @@
|
||||||
#define FG_SOUND_SAFETY_MULT 3
|
#define FG_SOUND_SAFETY_MULT 3
|
||||||
#define FG_MAX_SOUND_SAFETY ( 1.0 / FG_SOUND_SAFETY_MULT )
|
#define FG_MAX_SOUND_SAFETY ( 1.0 / FG_SOUND_SAFETY_MULT )
|
||||||
|
|
||||||
|
//
|
||||||
|
// SimpleSound
|
||||||
|
//
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
FGSimpleSound::FGSimpleSound( string file ) {
|
FGSimpleSound::FGSimpleSound( string file ) {
|
||||||
SGPath slfile( globals->get_fg_root() );
|
SGPath slfile( globals->get_fg_root() );
|
||||||
|
@ -60,6 +64,22 @@ FGSimpleSound::~FGSimpleSound() {
|
||||||
delete sample;
|
delete sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FGSimpleSound::play_once( slScheduler *sched ) {
|
||||||
|
sched->stopSample(sample);
|
||||||
|
sched->playSample(sample);
|
||||||
|
sched->addSampleEnvelope(sample, 0, 0, pitch_envelope, SL_PITCH_ENVELOPE);
|
||||||
|
sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FGSimpleSound::play_looped( slScheduler *sched ) {
|
||||||
|
sched->loopSample(sample);
|
||||||
|
sched->addSampleEnvelope(sample, 0, 0, pitch_envelope, SL_PITCH_ENVELOPE);
|
||||||
|
sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Sound Manager
|
||||||
|
//
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
FGSoundMgr::FGSoundMgr() {
|
FGSoundMgr::FGSoundMgr() {
|
||||||
|
@ -294,66 +314,46 @@ FGSimpleSound *FGSoundMgr::find( const string& refname ) {
|
||||||
// tell the scheduler to play the indexed sample in a continuous
|
// tell the scheduler to play the indexed sample in a continuous
|
||||||
// loop
|
// loop
|
||||||
bool FGSoundMgr::play_looped( const string& refname ) {
|
bool FGSoundMgr::play_looped( const string& refname ) {
|
||||||
sound_map_iterator it = sounds.find( refname );
|
FGSimpleSound *sample;
|
||||||
if ( it != sounds.end() ) {
|
|
||||||
FGSimpleSound *sample = it->second;
|
|
||||||
audio_sched->loopSample( sample->get_sample() );
|
|
||||||
audio_sched->addSampleEnvelope( sample->get_sample(), 0, 0,
|
|
||||||
sample->get_pitch_envelope(),
|
|
||||||
SL_PITCH_ENVELOPE );
|
|
||||||
audio_sched->addSampleEnvelope( sample->get_sample(), 0, 1,
|
|
||||||
sample->get_volume_envelope(),
|
|
||||||
SL_VOLUME_ENVELOPE );
|
|
||||||
|
|
||||||
return true;
|
if ((sample = find( refname )) == NULL)
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
sample->play(audio_sched, true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// tell the scheduler to play the indexed sample once
|
// tell the scheduler to play the indexed sample once
|
||||||
bool FGSoundMgr::play_once( const string& refname ) {
|
bool FGSoundMgr::play_once( const string& refname ) {
|
||||||
sound_map_iterator it = sounds.find( refname );
|
FGSimpleSound *sample;
|
||||||
if ( it != sounds.end() ) {
|
|
||||||
FGSimpleSound *sample = it->second;
|
|
||||||
audio_sched->stopSample( sample->get_sample() );
|
|
||||||
audio_sched->playSample( sample->get_sample() );
|
|
||||||
audio_sched->addSampleEnvelope( sample->get_sample(), 0, 0,
|
|
||||||
sample->get_pitch_envelope(),
|
|
||||||
SL_PITCH_ENVELOPE );
|
|
||||||
audio_sched->addSampleEnvelope( sample->get_sample(), 0, 1,
|
|
||||||
sample->get_volume_envelope(),
|
|
||||||
SL_VOLUME_ENVELOPE );
|
|
||||||
|
|
||||||
return true;
|
if ((sample = find( refname )) == NULL)
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
sample->play(audio_sched, false);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// return true of the specified sound is currently being played
|
// return true of the specified sound is currently being played
|
||||||
bool FGSoundMgr::is_playing( const string& refname ) {
|
bool FGSoundMgr::is_playing( const string& refname ) {
|
||||||
sound_map_iterator it = sounds.find( refname );
|
FGSimpleSound *sample;
|
||||||
if ( it != sounds.end() ) {
|
|
||||||
FGSimpleSound *sample = it->second;
|
if ((sample = find( refname )) == NULL)
|
||||||
return (sample->get_sample()->getPlayCount() > 0 );
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
return sample->is_playing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// immediate stop playing the sound
|
// immediate stop playing the sound
|
||||||
bool FGSoundMgr::stop( const string& refname ) {
|
bool FGSoundMgr::stop( const string& refname ) {
|
||||||
sound_map_iterator it = sounds.find( refname );
|
FGSimpleSound *sample;
|
||||||
if ( it != sounds.end() ) {
|
|
||||||
FGSimpleSound *sample = it->second;
|
if ((sample = find( refname )) == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
audio_sched->stopSample( sample->get_sample() );
|
audio_sched->stopSample( sample->get_sample() );
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,14 @@ SG_USING_STD(string);
|
||||||
// manages everything we need to know for an individual sound sample
|
// manages everything we need to know for an individual sound sample
|
||||||
class FGSimpleSound {
|
class FGSimpleSound {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
slSample *sample;
|
slSample *sample;
|
||||||
slEnvelope *pitch_envelope;
|
slEnvelope *pitch_envelope;
|
||||||
slEnvelope *volume_envelope;
|
slEnvelope *volume_envelope;
|
||||||
double pitch;
|
double pitch;
|
||||||
double volume;
|
double volume;
|
||||||
|
int clients;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -62,6 +65,20 @@ public:
|
||||||
FGSimpleSound( unsigned char *buffer, int len );
|
FGSimpleSound( unsigned char *buffer, int len );
|
||||||
~FGSimpleSound();
|
~FGSimpleSound();
|
||||||
|
|
||||||
|
void play_once( slScheduler *sched );
|
||||||
|
void play_looped( slScheduler *sched );
|
||||||
|
|
||||||
|
inline void play( slScheduler *sched, bool looped ) {
|
||||||
|
if (looped) play_looped( sched );
|
||||||
|
else play_once( sched );
|
||||||
|
}
|
||||||
|
inline void stop( slScheduler *sched ) {
|
||||||
|
sched->stopSample( sample );
|
||||||
|
}
|
||||||
|
inline bool is_playing( ) {
|
||||||
|
return (sample->getPlayCount() > 0 );
|
||||||
|
}
|
||||||
|
|
||||||
inline double get_pitch() const { return pitch; }
|
inline double get_pitch() const { return pitch; }
|
||||||
inline void set_pitch( double p ) {
|
inline void set_pitch( double p ) {
|
||||||
pitch = p;
|
pitch = p;
|
||||||
|
@ -167,6 +184,9 @@ public:
|
||||||
|
|
||||||
// immediate stop playing the sound
|
// immediate stop playing the sound
|
||||||
bool stop( const string& refname );
|
bool stop( const string& refname );
|
||||||
|
|
||||||
|
// return the audio scheduler
|
||||||
|
inline slScheduler *get_scheduler( ) { return audio_sched; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue