예제 #1
0
        private void initialiseStream()
        {
            if (this.stream != null)
            {
                throw new InvalidOperationException("You can not have two streams running at the same time.");
            }

            this.stream = new OggStream(this.file);
            this.stream.Prepare();
            this.stream.Finished += this.onStreamFinish;

            this.stream.Volume      = this.volume;
            this.stream.Pitch       = this.pitch;
            this.stream.LowPassGain = this.lowPassGain;
            this.stream.IsLooped    = this.looping;
        }
예제 #2
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);
        }
예제 #3
0
        private void onStreamFinish(object sender, EventArgs e)
        {
            if (this.looping)
            {
                return;
            }

            this.finished = true;
            lock (this.streamDisposeMutex)
            {
                this.stream.Dispose();
                this.stream = null;
            }

            if (this.prepareBuffer)
            {
                this.initialiseStream();
            }
        }
예제 #4
0
 /// <summary>
 /// Removes a stream from the manager.
 /// </summary>
 /// <param name="stream">The stream to be removed.</param>
 /// <returns>Whether the stream was removed succesfully.</returns>
 public bool RemoveStream(OggStream stream)
 {
     lock (this.iterationMutex)
         return(this.streams.Remove(stream));
 }
예제 #5
0
 /// <summary>
 /// Adds a new stream to be manager by the streamer.
 /// </summary>
 /// <param name="stream">The new stream to be managed.</param>
 /// <returns>Whether the stream was added succesfully.</returns>
 public bool AddStream(OggStream stream)
 {
     lock (this.iterationMutex)
         return(this.streams.Add(stream));
 }