]> git.mxchange.org Git - simgear.git/commitdiff
Fix runtime switching of sound devices.
authorehofman <ehofman>
Wed, 2 Dec 2009 08:32:59 +0000 (08:32 +0000)
committerTim Moore <timoore@redhat.com>
Thu, 3 Dec 2009 05:38:12 +0000 (06:38 +0100)
simgear/sound/sample_group.cxx
simgear/sound/soundmgr_openal.cxx

index de173dbdf770c2d9b2539a770c91fbb945799d3b..72ea9a5332216c10813c5876f8722546b61355a2 100644 (file)
@@ -271,17 +271,21 @@ SGSampleGroup::stop ()
         SGSoundSample *sample = sample_current->second;
 
         if ( sample->is_valid_source() ) {
         SGSoundSample *sample = sample_current->second;
 
         if ( sample->is_valid_source() ) {
+            ALint source = sample->get_source();
             if ( sample->is_playing() ) {
             if ( sample->is_playing() ) {
-                alSourcePause( sample->get_source() );
+                alSourceStop( source );
+                alSourcei( source, AL_BUFFER, 0 );
             }
             }
-            _smgr->release_source( sample->get_source() );
+            _smgr->release_source( source );
             sample->no_valid_source();
             sample->no_valid_source();
+        }
 
 
+        if (sample->is_valid_buffer() ) {
             _smgr->release_buffer( sample );
             sample->no_valid_buffer();
         }
     }
             _smgr->release_buffer( sample );
             sample->no_valid_buffer();
         }
     }
-    testForALError("suspend");
+    testForALError("stop");
 }
 
 // resume playing all associated samples
 }
 
 // resume playing all associated samples
index 6ead4d196a4602b34fd237903510fc479bdebdd6..6100dfcf78d37c30e5990f9227f5a1e5167ec287 100644 (file)
@@ -186,27 +186,36 @@ void SGSoundMgr::activate() {
 
 // stop the sound manager
 void SGSoundMgr::stop() {
 
 // stop the sound manager
 void SGSoundMgr::stop() {
-    if (_working) {
-        _working = false;
-        _active = false;
 
 
-        // clear any OpenAL buffers before shutting down
-        buffer_map_iterator buffers_current = _buffers.begin();
-        buffer_map_iterator buffers_end = _buffers.end();
-        for ( ; buffers_current != buffers_end; ++buffers_current ) {
-            refUint ref = buffers_current->second;
-            ALuint buffer = ref.id;
-            alDeleteBuffers(1, &buffer);
-        }
-        _buffers.clear();
+    // first stop all sample groups
+    sample_group_map_iterator sample_grp_current = _sample_groups.begin();
+    sample_group_map_iterator sample_grp_end = _sample_groups.end();
+    for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) {
+        SGSampleGroup *sgrp = sample_grp_current->second;
+        sgrp->stop();
+    }
 
 
-        sample_group_map_iterator sample_grp_current = _sample_groups.begin();
-        sample_group_map_iterator sample_grp_end = _sample_groups.end();
-        for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) {
-            SGSampleGroup *sgrp = sample_grp_current->second;
-            sgrp->stop();
-        }
+    // clear all OpenAL sources
+    for (unsigned int i=0; i<_free_sources.size(); i++) {
+        ALuint source = _free_sources[i];
+        alDeleteSources( 1 , &source );
+    }
+    _free_sources.clear();
 
 
+    // clear any OpenAL buffers before shutting down
+    buffer_map_iterator buffers_current = _buffers.begin();
+    buffer_map_iterator buffers_end = _buffers.end();
+    for ( ; buffers_current != buffers_end; ++buffers_current ) {
+        refUint ref = buffers_current->second;
+        ALuint buffer = ref.id;
+        alDeleteBuffers(1, &buffer);
+        _buffers.erase( buffers_current );
+    }
+    _buffers.clear();
+
+    if (_working) {
+        _working = false;
+        _active = false;
         _context = alcGetCurrentContext();
         _device = alcGetContextsDevice(_context);
         alcDestroyContext(_context);
         _context = alcGetCurrentContext();
         _device = alcGetContextsDevice(_context);
         alcDestroyContext(_context);