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 (check == 0) {
|
||||
if (!check) {
|
||||
_active = false;
|
||||
if (mgr->is_playing(_name)) {
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Stopping sound: " << _name);
|
||||
|
@ -298,7 +298,7 @@ FGSound::update (int dt)
|
|||
} else { // FLIPFLOP, RAISE, FALL
|
||||
|
||||
bool check = (int)(_offset + _property->getFloatValue() * _factor);
|
||||
if ((bool)check == _active)
|
||||
if (check == _active)
|
||||
return;
|
||||
|
||||
//
|
||||
|
@ -390,9 +390,9 @@ FGSound::update (int dt)
|
|||
_active = !_active;
|
||||
|
||||
if (_mode == FGSound::ONCE)
|
||||
mgr->play_once(_name);
|
||||
_sample->play(mgr->get_scheduler(), false);
|
||||
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_BULK,
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
#define FG_SOUND_SAFETY_MULT 3
|
||||
#define FG_MAX_SOUND_SAFETY ( 1.0 / FG_SOUND_SAFETY_MULT )
|
||||
|
||||
//
|
||||
// SimpleSound
|
||||
//
|
||||
|
||||
// constructor
|
||||
FGSimpleSound::FGSimpleSound( string file ) {
|
||||
SGPath slfile( globals->get_fg_root() );
|
||||
|
@ -60,6 +64,22 @@ FGSimpleSound::~FGSimpleSound() {
|
|||
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
|
||||
FGSoundMgr::FGSoundMgr() {
|
||||
|
@ -294,66 +314,46 @@ FGSimpleSound *FGSoundMgr::find( const string& refname ) {
|
|||
// tell the scheduler to play the indexed sample in a continuous
|
||||
// loop
|
||||
bool FGSoundMgr::play_looped( const string& refname ) {
|
||||
sound_map_iterator it = sounds.find( refname );
|
||||
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;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
FGSimpleSound *sample;
|
||||
|
||||
if ((sample = find( refname )) == NULL)
|
||||
return false;
|
||||
|
||||
sample->play(audio_sched, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// tell the scheduler to play the indexed sample once
|
||||
bool FGSoundMgr::play_once( const string& refname ) {
|
||||
sound_map_iterator it = sounds.find( refname );
|
||||
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;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
FGSimpleSound *sample;
|
||||
|
||||
if ((sample = find( refname )) == NULL)
|
||||
return false;
|
||||
|
||||
sample->play(audio_sched, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// return true of the specified sound is currently being played
|
||||
bool FGSoundMgr::is_playing( const string& refname ) {
|
||||
sound_map_iterator it = sounds.find( refname );
|
||||
if ( it != sounds.end() ) {
|
||||
FGSimpleSound *sample = it->second;
|
||||
return (sample->get_sample()->getPlayCount() > 0 );
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
FGSimpleSound *sample;
|
||||
|
||||
if ((sample = find( refname )) == NULL)
|
||||
return false;
|
||||
|
||||
return sample->is_playing();
|
||||
}
|
||||
|
||||
|
||||
// immediate stop playing the sound
|
||||
bool FGSoundMgr::stop( const string& refname ) {
|
||||
sound_map_iterator it = sounds.find( refname );
|
||||
if ( it != sounds.end() ) {
|
||||
FGSimpleSound *sample = it->second;
|
||||
audio_sched->stopSample( sample->get_sample() );
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
FGSimpleSound *sample;
|
||||
|
||||
if ((sample = find( refname )) == NULL)
|
||||
return false;
|
||||
|
||||
audio_sched->stopSample( sample->get_sample() );
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -50,11 +50,14 @@ SG_USING_STD(string);
|
|||
// manages everything we need to know for an individual sound sample
|
||||
class FGSimpleSound {
|
||||
|
||||
private:
|
||||
|
||||
slSample *sample;
|
||||
slEnvelope *pitch_envelope;
|
||||
slEnvelope *volume_envelope;
|
||||
double pitch;
|
||||
double volume;
|
||||
int clients;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -62,15 +65,29 @@ public:
|
|||
FGSimpleSound( unsigned char *buffer, int len );
|
||||
~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 void set_pitch( double p ) {
|
||||
pitch = p;
|
||||
pitch_envelope->setStep( 0, 0.01, pitch );
|
||||
pitch = p;
|
||||
pitch_envelope->setStep( 0, 0.01, pitch );
|
||||
}
|
||||
inline double get_volume() const { return volume; }
|
||||
inline void set_volume( double v ) {
|
||||
volume = v;
|
||||
volume_envelope->setStep( 0, 0.01, volume );
|
||||
volume = v;
|
||||
volume_envelope->setStep( 0, 0.01, volume );
|
||||
}
|
||||
|
||||
inline slSample *get_sample() { return sample; }
|
||||
|
@ -167,6 +184,9 @@ public:
|
|||
|
||||
// immediate stop playing the sound
|
||||
bool stop( const string& refname );
|
||||
|
||||
// return the audio scheduler
|
||||
inline slScheduler *get_scheduler( ) { return audio_sched; };
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue