Let the game engine manage it's own sound scene. This is to fix bug 1415 (Patch...
[blender-staging.git] / intern / SoundSystem / openal / SND_OpenALDevice.cpp
index 9bdfeb73844b09d734affcc444add8275f75b4a6..dfac8333a338796c29f22d6b95576f71a6bf6a35 100644 (file)
@@ -205,6 +205,8 @@ ALvoid alutUnloadWAV(ALenum format,ALvoid *data,ALsizei size,ALsizei freq)
 
 
 SND_OpenALDevice::SND_OpenALDevice()
+       : m_context(NULL),
+         m_device(NULL)
 {
     /* Removed the functionality for checking if noaudio was provided on */
     /* the commandline. */
@@ -229,6 +231,7 @@ SND_OpenALDevice::SND_OpenALDevice()
                        if (m_context) {
                                alcMakeContextCurrent(m_context);
                                m_audio = true;
+                               m_device = dev;
                        }
                }
 
@@ -302,13 +305,16 @@ void SND_OpenALDevice::MakeCurrent() const
 SND_OpenALDevice::~SND_OpenALDevice()
 {
        if (m_context) {
-               alcMakeContextCurrent(m_context);
-
+               MakeCurrent();
+               
                if (m_buffersinitialized)
                        alDeleteBuffers(NUM_BUFFERS, m_buffers);
 
                if (m_sourcesinitialized)
                        alDeleteSources(NUM_SOURCES, m_sources);
+               
+               alcDestroyContext(m_context);
+               m_context = NULL;
        }
        
        // let's see if we used the cd. if not, just leave it alone
@@ -323,6 +329,13 @@ SND_OpenALDevice::~SND_OpenALDevice()
        if (m_cdrom)
                delete m_cdrom;
 #endif
+#ifdef OUDE_OPENAL
+       if (m_audio)
+               alutExit();
+#else
+       if (m_device)
+               alcCloseDevice((ALCdevice*) m_device);
+#endif
 }
 
 
@@ -570,7 +583,7 @@ void SND_OpenALDevice::StopObject(int id) const
 
        alSourcefv(m_sources[id], AL_POSITION, obpos);
        alSourcefv(m_sources[id], AL_VELOCITY, obvel);
-       
+
        alSourcef(m_sources[id], AL_GAIN, 1.0);
        alSourcef(m_sources[id], AL_PITCH, 1.0);
        alSourcei(m_sources[id], AL_LOOPING, AL_FALSE);