Ejemplo n.º 1
0
        /// <summary>
        /// Evaluates a function and then checks for an OpenAL error.
        /// </summary>
        /// <param name="function">The function to be evaluated.</param>
        /// <param name="parameter">The type of the parameter of the function.</param>
        /// <typeparam name="TParameter">The type of the parameter of the function.</typeparam>
        /// <typeparam name="TReturn">The type of the return value.</typeparam>
        public static TReturn Eval <TParameter, TReturn>(Func <TParameter, TReturn> function, TParameter parameter)
        {
            var val = function(parameter);

            ALHelper.Check();
            return(val);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Evaluates a function and then checks for an OpenAL error.
        /// </summary>
        /// <param name="function">The function to be evaluated.</param>
        /// <typeparam name="TReturn">The type of the return value.</typeparam>
        public static TReturn Eval <TReturn>(Func <TReturn> function)
        {
            var val = function();

            ALHelper.Check();
            return(val);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Removes all the processed buffers from the source.
        /// </summary>
        /// <returns>An integer array of buffer handles that are removed.</returns>
        public int[] UnqueueProcessedBuffers()
        {
            var unqueued = AL.SourceUnqueueBuffers(this.Handle, this.ProcessedBuffers);

            ALHelper.Check();
            return(unqueued);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Disposes this stream.
        /// </summary>
        public void Dispose()
        {
            var state = this.Source.State;

            if (state == ALSourceState.Playing || state == ALSourceState.Paused)
            {
                this.stopPlayback();
            }

            lock (this.PrepareMutex)
            {
                OggStreamer.Instance.RemoveStream(this);

                if (state != ALSourceState.Initial)
                {
                    this.empty();
                }

                this.close();

                this.underlyingStream.Dispose();
            }

            this.Source.Dispose();
            this.Buffer.Dispose();

            ALHelper.Check();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new OpenAL source.
        /// </summary>
        public Source()
        {
            this.Handle = AL.GenSource();
            ALHelper.Check();

            this.volume = 1;
            this.pitch  = 1;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fills the buffer with new data.
        /// </summary>
        /// <param name="index">The starting index from where to fill the buffer.</param>
        /// <param name="data">The new content of the buffers.</param>
        /// <param name="format">The format the buffers are in.</param>
        /// <param name="sampleRate">The samplerate of the buffers.</param>
        public void FillBuffer(int index, short[] data, ALFormat format, int sampleRate)
        {
            if (index < 0 || index >= this.Handles.Length)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            ALHelper.Call(() => AL.BufferData(this.Handles[index], format, data, data.Length * sizeof(short), sampleRate));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Removes all the buffers from the source.
        /// </summary>
        public void UnqueueBuffers()
        {
            if (this.QueuedBuffers == 0)
            {
                return;
            }

            AL.SourceUnqueueBuffers(this.Handle, this.QueuedBuffers);
            ALHelper.Check();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Disposes the buffer.
        /// </summary>
        public void Dispose()
        {
            if (this.Disposed)
            {
                return;
            }

            ALHelper.Call(AL.DeleteBuffers, this.Handles);

            this.Disposed = true;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Stops playing the source and frees allocated resources.
        /// </summary>
        public void Dispose()
        {
            if (this.Disposed)
            {
                return;
            }

            if (this.State != ALSourceState.Stopped)
            {
                this.Stop();
            }

            AL.DeleteSource(this.Handle);
            ALHelper.Check();
            this.Disposed = true;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Fills the buffers of the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="bufferId">The id of the buffer to be filled.</param>
        /// <returns></returns>
        public bool FillBuffer(OggStream stream, int bufferId)
        {
            int readSamples;

            lock (this.readMutex)
            {
                readSamples = stream.Reader.ReadSamples(this.readSampleBuffer, 0, this.BufferSize);
                SoundBufferData.CastBuffer(this.readSampleBuffer, this.castBuffer, readSamples);
            }
            if (readSamples > 0)
            {
                AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, this.castBuffer,
                              readSamples * sizeof(short), stream.Reader.SampleRate);
                ALHelper.Check();
            }

            return(readSamples != this.BufferSize);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Stops playing the source.
 /// </summary>
 public void Stop()
 {
     AL.SourceStop(this.Handle);
     ALHelper.Check();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Pauses playing the source.
 /// </summary>
 public void Pause()
 {
     AL.SourcePause(this.Handle);
     ALHelper.Check();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Starts playing the source.
 /// </summary>
 public void Play()
 {
     AL.SourcePlay(this.Handle);
     ALHelper.Check();
 }
Ejemplo n.º 14
0
 public void UnqueueBuffers(int[] bufferIDs)
 {
     AL.SourceUnqueueBuffers(this.Handle, this.QueuedBuffers, bufferIDs);
     ALHelper.Check();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Adds buffers to the end of the buffer queue of this source.
 /// </summary>
 /// <param name="bufferLength">The length each buffer has.</param>
 /// <param name="bufferIDs">The handles to the OpenAL buffers.</param>
 public void QueueBuffers(int bufferLength, int[] bufferIDs)
 {
     AL.SourceQueueBuffers(this.Handle, bufferLength, bufferIDs);
     ALHelper.Check();
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Adds buffers to the end of the buffer queue of this source.
 /// </summary>
 /// <param name="bufferID">The handle to the OpenAL buffer.</param>
 public void QueueBuffer(int bufferID)
 {
     AL.SourceQueueBuffer(this.Handle, bufferID);
     ALHelper.Check();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Generates a new sound buffer of the given size.
 /// </summary>
 /// <param name="amount">The amount of buffers to reserve.</param>
 public SoundBuffer(int amount)
 {
     this.Handles = ALHelper.Eval(AL.GenBuffers, amount);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Calls a function and then checks for an OpenAL error.
 /// </summary>
 /// <typeparam name="TParameter">The type of the parameter of the function.</typeparam>
 /// <param name="function">The function to be called.</param>
 /// <param name="parameter">The parameter to be passed to the function.</param>
 public static void Call <TParameter>(Action <TParameter> function, TParameter parameter)
 {
     function(parameter);
     ALHelper.Check();
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Calls a function and then checks for an OpenAL error.
 /// </summary>
 /// <param name="function">The function to be called.</param>
 public static void Call(Action function)
 {
     function();
     ALHelper.Check();
 }