Пример #1
0
        /// <summary>
        /// Fill a buffer with audio data in IEEE floating-point format.
        /// </summary>
        /// <param name="name">Name of the buffer.</param>
        /// <param name="channels">Indicates if the data is mono or stereo.</param>
        /// <param name="data">Floating-point data.</param>
        /// <param name="count">Number of samples to buffer.</param>
        /// <param name="freq">Playback frequency in samples per second.</param>
        public static void BufferData(uint name, Channels channels, float[] data, int count, int freq)
        {
            var format = channels == Channels.Mono ? AlBufferFormat.MonoFloat32 : AlBufferFormat.StereoFloat32;

            AL10.alBufferData(name, (int)format, data, count * 4, freq);
            AlHelper.AlAlwaysCheckError("alBufferData call failed.");
        }
Пример #2
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.");
 }
Пример #3
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);
 }
Пример #4
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);
 }
Пример #5
0
        /// <summary>
        /// Create an <see cref="AlStaticSource"/> for this context.
        /// </summary>
        public AlStaticSource CreateStaticSource()
        {
            ALC10.alcMakeContextCurrent(Handle);
            AL10.alGenSources(1, out var name);
            AlHelper.AlAlwaysCheckError("Call to alGenSources failed.");
            var source = new AlStaticSource(name, this);

            _sources.Add(source);
            return(source);
        }
Пример #6
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);
        }
Пример #7
0
 /// <summary>
 /// Create a number of OpenAL buffers for this device.
 /// </summary>
 /// <param name="buffers">Array to fill with buffer names.</param>
 /// <param name="n">Number of buffers to generate.</param>
 public void CreateBuffers(uint[] buffers, int n)
 {
     CheckDisposed();
     ALC10.alcMakeContextCurrent(MainContext.Handle);
     AL10.alGenBuffers(n, buffers);
     AlHelper.AlAlwaysCheckError("Failed to generate buffers.");
     for (var i = 0; i < n; i++)
     {
         _buffers.Add(buffers[i]);
     }
 }
Пример #8
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.");
        }
Пример #9
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.");
        }
Пример #10
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);
        }
Пример #11
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.");
        }
Пример #12
0
        /// <summary>
        /// Create a context for this device.
        /// </summary>
        public AlContext CreateContext()
        {
            CheckDisposed();
            var ctxHandle = ALC10.alcCreateContext(_handle, new int[0]);

            if (ctxHandle == IntPtr.Zero)
            {
                AlHelper.AlcCheckError(_handle, "Failed to create context.");
                throw new Exception("Failed to create context.");
            }
            var ctx = new AlContext(this, ctxHandle);

            _contexts.Add(ctx);
            return(ctx);
        }
Пример #13
0
 /// <summary>
 /// Fill a buffer with data.
 /// </summary>
 /// <param name="name">Name of the buffer.</param>
 /// <param name="format">Format of data in the buffer.</param>
 /// <param name="data">Data as a byte array.</param>
 /// <param name="freq">Playback frequency in samples per second.</param>
 public static void BufferData(uint name, AlBufferFormat format, byte[] data, int freq)
 {
     AL10.alBufferData(name, (int)format, data, data.Length, freq);
     AlHelper.AlAlwaysCheckError("alBufferData call failed.");
 }