Exemple #1
0
        public virtual void DeleteALBuffers()
        {
            Owner.KillChannels(this);
            if (alBuffer != 0)
            {
                if (!Al.IsBuffer(alBuffer))
                {
                    throw new Exception("Buffer to delete is invalid!");
                }

                Al.DeleteBuffer(alBuffer); alBuffer = 0;

                int alError = Al.GetError();
                if (alError != Al.NoError)
                {
                    throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
                }
            }
            if (alMuffledBuffer != 0)
            {
                if (!Al.IsBuffer(alMuffledBuffer))
                {
                    throw new Exception("Buffer to delete is invalid!");
                }

                Al.DeleteBuffer(alMuffledBuffer); alMuffledBuffer = 0;

                int alError = Al.GetError();
                if (alError != Al.NoError)
                {
                    throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
                }
            }
        }
 public static void ClearPool()
 {
     lock (bufferPool)
     {
         bufferPool.ForEach(b => Al.DeleteBuffer(b));
         bufferPool.Clear();
     }
     BuffersGenerated = 0;
 }
Exemple #3
0
        public virtual void Dispose()
        {
            if (disposed)
            {
                return;
            }

            Owner.KillChannels(this);
            if (alBuffer != 0)
            {
                if (!Al.IsBuffer(alBuffer))
                {
                    throw new Exception("Buffer to delete is invalid!");
                }

                Al.DeleteBuffer(alBuffer); alBuffer = 0;

                int alError = Al.GetError();
                if (alError != Al.NoError)
                {
                    throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
                }
            }
            if (alMuffledBuffer != 0)
            {
                if (!Al.IsBuffer(alMuffledBuffer))
                {
                    throw new Exception("Buffer to delete is invalid!");
                }

                Al.DeleteBuffer(alMuffledBuffer); alMuffledBuffer = 0;

                int alError = Al.GetError();
                if (alError != Al.NoError)
                {
                    throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
                }
            }

            Owner.RemoveSound(this);
            disposed = true;
        }
Exemple #4
0
        public void Dispose()
        {
            try
            {
                if (mutex != null)
                {
                    Monitor.Enter(mutex);
                }
                if (ALSourceIndex >= 0)
                {
                    Al.SourceStop(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
                    int alError = Al.GetError();
                    if (alError != Al.NoError)
                    {
                        throw new Exception("Failed to stop source: " + debugName + ", " + Al.GetErrorString(alError));
                    }

                    if (IsStream)
                    {
                        uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);

                        Al.SourceStop(alSource);
                        alError = Al.GetError();
                        if (alError != Al.NoError)
                        {
                            throw new Exception("Failed to stop streamed source: " + debugName + ", " + Al.GetErrorString(alError));
                        }

                        int buffersToRequeue = 0;

                        buffersToRequeue = 0;
                        Al.GetSourcei(alSource, Al.BuffersProcessed, out buffersToRequeue);
                        alError = Al.GetError();
                        if (alError != Al.NoError)
                        {
                            throw new Exception("Failed to determine processed buffers from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
                        }

                        Al.SourceUnqueueBuffers(alSource, buffersToRequeue, unqueuedBuffers);
                        alError = Al.GetError();
                        if (alError != Al.NoError)
                        {
                            throw new Exception("Failed to unqueue buffers from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
                        }

                        Al.Sourcei(alSource, Al.Buffer, 0);
                        alError = Al.GetError();
                        if (alError != Al.NoError)
                        {
                            throw new Exception("Failed to reset buffer for streamed source: " + debugName + ", " + Al.GetErrorString(alError));
                        }

                        for (int i = 0; i < 4; i++)
                        {
                            Al.DeleteBuffer(streamBuffers[i]);
                            alError = Al.GetError();
                            if (alError != Al.NoError)
                            {
                                throw new Exception("Failed to delete streamBuffers[" + i.ToString() + "] (" + streamBuffers[i].ToString() + "): " + debugName + ", " + Al.GetErrorString(alError));
                            }
                        }

                        reachedEndSample = true;
                    }
                    else
                    {
                        Al.Sourcei(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, 0);
                        alError = Al.GetError();
                        if (alError != Al.NoError)
                        {
                            throw new Exception("Failed to unbind buffer to non-streamed source: " + debugName + ", " + Al.GetErrorString(alError));
                        }
                    }

                    ALSourceIndex = -1;
                    debugName    += " [DISPOSED]";
                }
            }
            finally
            {
                if (mutex != null)
                {
                    Monitor.Exit(mutex);
                }
            }
        }
Exemple #5
0
 public void Dispose()
 {
     Al.DeleteBuffer(Buffer);
     GC.SuppressFinalize(this);
 }