[prev in list] [next in list] [prev in thread] [next in thread] 

List:       flightgear-devel
Subject:    [Flightgear-devel] OpenAL in SimGear - pause patch
From:       "Matias D'Ambrosio" <angasule () gmail ! com>
Date:       2009-05-27 2:29:54
Message-ID: 200905262329.55320.angasule () gmail ! com
[Download RAW message or body]

Sorry for not replying to my previous email, I think gmail is not showing it 
(or it was lost somewhere else...).

 This is a quick patch to have pause and resume working on alsoft and any 
other implementation. I just finished and haven't even tried to compile it, 
it's late and I have to install quite a few packages to be able to do it, so 
I'll try to test it tomorrow, sorry :-)
 The most obvious issue with this patch is that now the bool member of 
SGSoundSample called 'playing' is true whether it's paused or not. I think 
it's fine code-wise, but the name might mislead people. Maybe renaming it to 
'active' or something similar would make sense.

 I tried to maintain the coding style, and used 'cvs diff -u' to generate the 
patch. Comments welcome.
 Cheers,
  Matias D'Ambrosio

["pause.patch" (text/x-patch)]

Index: simgear/sound/sample_openal.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/sample_openal.cxx,v
retrieving revision 1.33
diff -u -r1.33 sample_openal.cxx
--- simgear/sound/sample_openal.cxx	12 Dec 2008 07:41:44 -0000	1.33
+++ simgear/sound/sample_openal.cxx	27 May 2009 01:58:30 -0000
@@ -230,6 +230,21 @@
 }
 
 
+// pause or unpause the sample
+void SGSoundSample::pause( bool _pause ) {
+    if ( playing ) {
+        if ( _pause) {
+            alSourcePause( source);
+            print_openal_error("play (alSourcePause)");
+        }
+        else {
+            alSourcePlay( source );
+            print_openal_error("play (alSourcePlay)");
+        }
+    }
+}
+
+
 // stop playing the sample
 void SGSoundSample::stop() {
     if (playing) {
Index: simgear/sound/sample_openal.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/sample_openal.hxx,v
retrieving revision 1.23
diff -u -r1.23 sample_openal.hxx
--- simgear/sound/sample_openal.hxx	23 Oct 2008 18:46:55 -0000	1.23
+++ simgear/sound/sample_openal.hxx	27 May 2009 01:58:30 -0000
@@ -151,6 +151,13 @@
     void play( bool _loop );
 
     /**
+     * Pause or unpause this sample.
+     *
+     * @param _pause Define whether the sound should be paused or unpaused.
+     */
+    void pause( bool _pause = true );
+
+    /**
      * Stop playing this sample.
      *
      * @param sched A pointer to the appropriate scheduler.
Index: simgear/sound/soundmgr_openal.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/soundmgr_openal.cxx,v
retrieving revision 1.29
diff -u -r1.29 soundmgr_openal.cxx
--- simgear/sound/soundmgr_openal.cxx	25 Jul 2008 18:35:42 -0000	1.29
+++ simgear/sound/soundmgr_openal.cxx	27 May 2009 01:58:30 -0000
@@ -188,7 +188,12 @@
 SGSoundMgr::pause ()
 {
     if (context) {
-        alcSuspendContext( context );
+        sample_map_iterator sample_current = samples.begin();
+        sample_map_iterator sample_end = samples.end();
+        for ( ; sample_current != sample_end; ++sample_current ) {
+            SGSoundSample *sample = sample_current->second;
+            sample->pause( true );
+        }
         if ( alGetError() != AL_NO_ERROR) {
 	    SG_LOG( SG_GENERAL, SG_ALERT,
                     "Oops AL error after soundmgr pause()!" );
@@ -201,7 +206,12 @@
 SGSoundMgr::resume ()
 {
     if (context) {
-        alcProcessContext( context );
+        sample_map_iterator sample_current = samples.begin();
+        sample_map_iterator sample_end = samples.end();
+        for ( ; sample_current != sample_end; ++sample_current ) {
+            SGSoundSample *sample = sample_current->second;
+            sample->pause( false );
+        }
         if ( alGetError() != AL_NO_ERROR) {
 	    SG_LOG( SG_GENERAL, SG_ALERT,
                     "Oops AL error after soundmgr resume()!" );


------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 

_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic