00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <simgear/misc/sg_path.hxx>
00025
00026 #include "sample_plib.hxx"
00027
00028
00029
00030
00031
00032
00033
00034 SGSoundSample::SGSoundSample( const char *path, const char *file )
00035 : sample(NULL),
00036 pitch_envelope(NULL),
00037 volume_envelope(NULL),
00038 pitch(1.0),
00039 volume(1.0)
00040 {
00041 SGPath slfile( path );
00042 if ( file )
00043 slfile.append( file );
00044
00045 sample = new slSample ( slfile.c_str() );
00046 pitch_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
00047 volume_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
00048 pitch_envelope->setStep ( 0, 0.01, 1.0 );
00049 volume_envelope->setStep ( 0, 0.01, 1.0 );
00050 }
00051
00052 SGSoundSample::SGSoundSample( unsigned char *buffer, int len )
00053 : pitch(1.0),
00054 volume(1.0)
00055 {
00056 sample = new slSample ( buffer, len );
00057 pitch_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
00058 volume_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
00059 pitch_envelope->setStep ( 0, 0.01, 1.0 );
00060 volume_envelope->setStep ( 0, 0.01, 1.0 );
00061 }
00062
00063
00064 SGSoundSample::~SGSoundSample() {
00065 delete pitch_envelope;
00066 delete volume_envelope;
00067 delete sample;
00068 }
00069
00070 void SGSoundSample::play( slScheduler *sched, bool looped ) {
00071
00072
00073 if ( sample->getPlayCount() > 0 ) {
00074 sched->stopSample(sample);
00075
00076 }
00077
00078 if ( looped ) {
00079 sched->loopSample(sample);
00080 } else {
00081 sched->playSample(sample);
00082 }
00083
00084 sched->addSampleEnvelope(sample, 0, 0, pitch_envelope, SL_PITCH_ENVELOPE);
00085 sched->addSampleEnvelope(sample, 0, 1, volume_envelope, SL_VOLUME_ENVELOPE);
00086 }
00087
00088 void SGSoundSample::stop( slScheduler *sched ) {
00089
00090 sched->stopSample( sample );
00091 }