]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/soundmgr_openal.cxx
a few more temporarty debugging statements
[simgear.git] / simgear / sound / soundmgr_openal.cxx
index eb0a76e409d8b63a7eda13f0d1ee989b3aea05a0..b22a18350616cfc01156624077c2135c288fefa9 100644 (file)
@@ -94,6 +94,7 @@ SGSoundMgr::~SGSoundMgr() {
 // initialize the sound manager
 void SGSoundMgr::init() {
 
+printf("Initializing OpenAL sound manager\n");
     SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" );
 
     ALCdevice *device = alcOpenDevice(_devname);
@@ -114,6 +115,8 @@ void SGSoundMgr::init() {
         return;
     }
 
+    if (_context != NULL)
+        SG_LOG(SG_GENERAL, SG_ALERT, "context is already assigned");
     _context = context;
     _working = true;
 
@@ -151,21 +154,28 @@ void SGSoundMgr::init() {
         else break;
     }
 
+printf("%i free sources found\n", _free_sources.size() );
     if (_free_sources.size() == 0) {
         SG_LOG(SG_GENERAL, SG_ALERT, "Unable to grab any OpenAL sources!");
     }
+}
 
-    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->activate();
+void SGSoundMgr::activate() {
+    if ( _working ) {
+        _active = true;
+        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->activate();
+        }
     }
 }
 
 // stop the sound manager
 void SGSoundMgr::stop() {
     if (_working) {
+printf("Stopping Sound Manager\n");
         _working = false;
         _active = false;
 
@@ -187,7 +197,8 @@ void SGSoundMgr::stop() {
 }
 
 void SGSoundMgr::suspend() {
-    if (_active) {
+    if (_working) {
+printf("SoundManager suspend\n");
         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 ) {
@@ -199,7 +210,8 @@ void SGSoundMgr::suspend() {
 }
 
 void SGSoundMgr::resume() {
-    if (!_active) {
+    if (_working) {
+printf("SoundManager resume\n");
         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 ) {
@@ -212,6 +224,7 @@ void SGSoundMgr::resume() {
 
 void SGSoundMgr::bind ()
 {
+printf("SoundManager bind\n");
     _free_sources.clear();
     _free_sources.reserve( MAX_SOURCES );
     _sources_in_use.clear();
@@ -221,11 +234,12 @@ void SGSoundMgr::bind ()
 
 void SGSoundMgr::unbind ()
 {
+printf("SoundManager unbind\n");
     _sample_groups.clear();
 
     // delete free sources
     for (unsigned int i=0; i<_free_sources.size(); i++) {
-        ALuint source = _free_sources.at( i );
+        ALuint source = _free_sources[i];
         alDeleteSources( 1 , &source );
     }
 
@@ -264,7 +278,7 @@ bool SGSoundMgr::add( SGSampleGroup *sgrp, const string& refname )
         return false;
     }
 
-    if (_working) sgrp->activate();
+    if (_active) sgrp->activate();
     _sample_groups[refname] = sgrp;
 
     return true;
@@ -280,7 +294,7 @@ bool SGSoundMgr::remove( const string &refname )
         return false;
     }
 
-    _sample_groups.erase( refname );
+    _sample_groups.erase( sample_grp_it );
 
     return true;
 }
@@ -386,8 +400,9 @@ void SGSoundMgr::release_source( unsigned int source )
             alSourceStop( source );
         testForALError("release source");
 
-        _free_sources.push_back(source);
-        _sources_in_use.erase(it, it+1);
+        alSourcei( source, AL_BUFFER, 0 );
+        _free_sources.push_back( source );
+        _sources_in_use.erase( it );
     }
 }
 
@@ -465,8 +480,8 @@ void SGSoundMgr::release_buffer(SGSoundSample *sample)
     buffer_it->second.refctr--;
     if (buffer_it->second.refctr == 0) {
         ALuint buffer = buffer_it->second.id;
-        _buffers.erase( sample_name );
         alDeleteBuffers(1, &buffer);
+        _buffers.erase( buffer_it );
         testForALError("release buffer");
     }
 }