]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_group.cxx
.. and remove some debugging code
[simgear.git] / simgear / sound / sample_group.cxx
index 5d460be11b763270e7b0812d0777e677fb7b7a05..ed4d466b8b8fa0a274f01d4a2b95968c899dd351 100644 (file)
@@ -146,7 +146,6 @@ void SGSampleGroup::update( double dt ) {
                 continue;
 
             // start playing the sample
-            ALboolean looping = sample->get_looping() ? AL_TRUE : AL_FALSE;
             ALuint buffer = sample->get_buffer();
             ALuint source = _smgr->request_source();
             if (alIsSource(source) == AL_TRUE && alIsBuffer(buffer) == AL_TRUE)
@@ -159,9 +158,10 @@ void SGSampleGroup::update( double dt ) {
                 sample->set_source( source );
                 update_sample_config( sample );
 
-                alSourcei( source, AL_SOURCE_RELATIVE, AL_FALSE );
+                ALboolean looping = sample->get_looping() ? AL_TRUE : AL_FALSE;
                 alSourcei( source, AL_LOOPING, looping );
                 alSourcef( source, AL_ROLLOFF_FACTOR, 1.0 );
+                alSourcei( source, AL_SOURCE_RELATIVE, AL_FALSE );
                 alSourcePlay( source );
                 testForALError("sample play");
             } else {
@@ -169,14 +169,15 @@ void SGSampleGroup::update( double dt ) {
                    SG_LOG( SG_GENERAL, SG_ALERT, "No such buffer!\n");
                 // sample->no_valid_source();
                 // sadly, no free source available at this time
+printf("No free source found.");
             }
 
         } else if ( sample->is_valid_source() && sample->has_changed() ) {
             if ( !sample->is_playing() ) {
                 // a request to stop playing the sound has been filed.
 
-                sample->no_valid_source();
                 sample->stop();
+                sample->no_valid_source();
                 _smgr->release_source( sample->get_source() );
             } else  {
                 update_sample_config( sample );
@@ -191,9 +192,10 @@ void SGSampleGroup::update( double dt ) {
             alGetSourcei( source, AL_SOURCE_STATE, &result );
             if ( result == AL_STOPPED ) {
                 // sample is stoped because it wasn't looping
-                sample->no_valid_source();
                 sample->stop();
+                sample->no_valid_source();
                 _smgr->release_source( source );
+                _smgr->release_buffer( sample );
             }
         }
         testForALError("update");
@@ -223,7 +225,8 @@ bool SGSampleGroup::remove( const string &refname ) {
         return false;
     }
 
-    _removed_samples.push_back( sample_it->second );
+    if ( sample_it->second->is_valid_buffer() )
+        _removed_samples.push_back( sample_it->second );
     _samples.erase( sample_it );
 
     return true;