// manages everything we need to know for an individual sound sample
class FGSimpleSound {
+private:
+
slSample *sample;
slEnvelope *pitch_envelope;
slEnvelope *volume_envelope;
FGSimpleSound( unsigned char *buffer, int len );
~FGSimpleSound();
+ void play( slScheduler *sched, bool looped );
+ void stop( slScheduler *sched, bool quick = true );
+
+ inline void play_once( slScheduler *sched ) { play( sched, false); }
+ inline void play_looped( slScheduler *sched ) { play( sched, true); }
+ 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; }
};
+typedef struct {
+ int n;
+ slSample *sample;
+} sample_ref;
+
+typedef map < string, sample_ref * > sample_map;
+typedef sample_map::iterator sample_map_iterator;
+typedef sample_map::const_iterator const_sample_map_iterator;
+
+
typedef map < string, FGSimpleSound * > sound_map;
typedef sound_map::iterator sound_map_iterator;
typedef sound_map::const_iterator const_sound_map_iterator;
slScheduler *audio_sched;
smMixer *audio_mixer;
+
sound_map sounds;
+ sample_map samples;
SGTimeStamp last;
double safety;
/**
* Run the audio scheduler.
*/
- void update();
+ void update(double dt);
+
+
+ /**
+ * Pause all sounds.
+ */
+ void pause ();
+
+
+ /**
+ * Resume all sounds.
+ */
+ void resume ();
// is audio working?
- inline bool is_working() const { return !audio_sched->not_working(); }
+ inline bool is_working() const { return !audio_sched->notWorking(); }
// add a sound effect, return true if successful
- bool add( FGSimpleSound *sound, const string& refname );
+ bool add( FGSimpleSound *sound, const string& refname);
+
+ // add a sound file, return the sample if successful, else return NULL
+ FGSimpleSound *add( const string& refname, const string& file = "" );
// remove a sound effect, return true if successful
bool remove( const string& refname );
// immediate stop playing the sound
bool stop( const string& refname );
+
+ // return the audio scheduler
+ inline slScheduler *get_scheduler( ) { return audio_sched; };
};