示例#1
0
 /// <summary>
 /// Queue a buffer.
 /// </summary>
 /// <param name="name">Name of the buffer.</param>
 public void QueueBuffer(uint name)
 {
     CheckDisposed();
     Context.MakeCurrent();
     AL10.alSourceQueueBuffers(Name, 1, ref name);
     AlHelper.AlCheckError("alSourceQueueBuffers call failed.");
 }
示例#2
0
 /// <summary>
 /// Get the number of processed buffers.
 /// </summary>
 public int ProcessedBuffers()
 {
     CheckDisposed();
     Context.MakeCurrent();
     AL10.alGetSourcei(Name, AL10.AL_BUFFERS_PROCESSED, out var processed);
     AlHelper.AlCheckError("Failed to get number of processed buffers.");
     return(processed);
 }
示例#3
0
 internal void DeleteSource(AlSource source)
 {
     if (!_sources.Remove(source))
     {
         throw new InvalidOperationException("Context does not own the given source.");
     }
     AL10.alDeleteSources(1, ref source.Name);
     AlHelper.AlCheckError("Call to alDeleteSources failed.");
     _sources.Remove(source);
 }
示例#4
0
        /// <summary>
        /// Unqueue one buffer.
        /// </summary>
        /// <returns>Name of the buffer or 0 if no buffer was queued.</returns>
        public uint UnqueueBuffer()
        {
            CheckDisposed();
            Context.MakeCurrent();
            uint name = 0;

            AL10.alSourceUnqueueBuffers(Name, 1, ref name);
            AlHelper.AlCheckError("alSourceUnqueueBuffers call failed.");
            return(name);
        }
示例#5
0
        /// <summary>
        /// Delete a buffer.
        /// </summary>
        /// <param name="name">Name of the buffer.</param>
        /// <exception cref="InvalidOperationException">If the buffer is not owned by this device.</exception>
        public void DeleteBuffer(uint name)
        {
            CheckDisposed();

            if (!_buffers.Remove(name))
            {
                throw new InvalidOperationException("Device does not own given buffer.");
            }

            ALC10.alcMakeContextCurrent(MainContext.Handle);
            AL10.alDeleteBuffers(1, ref name);
            AlHelper.AlCheckError("alDeleteBuffers call failed.");
        }
示例#6
0
        /// <summary>
        /// Unqueues all buffers and set the given buffer to be the current buffer.
        /// Does nothing in <see cref="AL10.AL_PLAYING"/> and <see cref="AL10.AL_PAUSED"/> states.
        /// </summary>
        /// <param name="name">Name of the buffer to set.</param>
        public void SetBuffer(uint name)
        {
            var ss = SourceState;

            if (ss == SourceState.Playing || ss == SourceState.Paused)
            {
                return;
            }

            CheckDisposed();
            Context.MakeCurrent();
            AL10.alSourcei(Name, AL10.AL_BUFFER, (int)name);
            AlHelper.AlCheckError("Setting buffer failed.");
        }
示例#7
0
        /// <summary>
        /// Create an OpenAL buffer for this device.
        /// </summary>
        public uint CreateBuffer()
        {
            CheckDisposed();
            ALC10.alcMakeContextCurrent(MainContext.Handle);
            AL10.alGenBuffers(1, out var name);
            if (name == 0)
            {
                AlHelper.AlCheckError("alGenBuffer call failed.");
                throw new Exception("Failed to create buffer.");
            }

            _buffers.Add(name);
            return(name);
        }
示例#8
0
        /// <summary>
        /// Delete a collection of buffers.
        /// </summary>
        /// <param name="buffers">Array to delete buffers from, starting at index 0.</param>
        /// <param name="n">Number of buffers to delete.</param>
        /// <remarks>
        /// Buffers that are not owned by this device are ignored.
        /// </remarks>
        /// <exception cref="IndexOutOfRangeException">
        /// If <paramref name="n"/> is larger than or equal to <code>buffers.Length</code>.
        /// </exception>
        public void DeleteBuffers(uint[] buffers, int n)
        {
            CheckDisposed();
            ALC10.alcMakeContextCurrent(MainContext.Handle);

            for (var i = 0; i < n; i++)
            {
                var buffer = buffers[i];
                if (_buffers.Remove(buffer))
                {
                    AL10.alDeleteBuffers(1, ref buffer);
                }
            }
            AlHelper.AlCheckError("alDeleteBuffers call failed.");
        }