00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef _SG_SAMPLE_HXX
00029 #define _SG_SAMPLE_HXX 1
00030
00031 #ifndef __cplusplus
00032 # error This library requires C++
00033 #endif
00034
00035 #include <simgear/compiler.h>
00036
00037 #include <plib/sl.h>
00038
00039
00044 class SGSoundSample {
00045
00046 private:
00047
00048 slSample *sample;
00049 slEnvelope *pitch_envelope;
00050 slEnvelope *volume_envelope;
00051 double pitch;
00052 double volume;
00053
00054 public:
00055
00056 SGSoundSample( const char *path, const char *file = NULL );
00057 SGSoundSample( unsigned char *buffer, int len );
00058 ~SGSoundSample();
00059
00066 void play( slScheduler *sched, bool looped );
00067
00073 void stop( slScheduler *sched );
00074
00079 inline void play_once( slScheduler *sched ) { play( sched, false); }
00080
00085 inline void play_looped( slScheduler *sched ) { play( sched, true); }
00086
00091 inline bool is_playing( ) {
00092 return ( sample->getPlayCount() > 0 );
00093 }
00094
00098 inline double get_pitch() const { return pitch; }
00099
00103 inline void set_pitch( double p ) {
00104 pitch = p;
00105 pitch_envelope->setStep( 0, 0.01, pitch );
00106 }
00107
00111 inline double get_volume() const { return volume; }
00112
00116 inline void set_volume( double v ) {
00117 volume = v;
00118 volume_envelope->setStep( 0, 0.01, volume );
00119 }
00120
00124 inline slSample *get_sample() { return sample; }
00125
00129 inline slEnvelope *get_pitch_envelope() { return pitch_envelope; }
00130
00134 inline slEnvelope *get_volume_envelope() { return volume_envelope; }
00135 };
00136
00137
00138 #endif // _SG_SAMPLE_HXX
00139
00140