public void Play() { var state = AL.GetSourceState(alSourceId); ALHelper.CheckError("Failed to get source state."); switch (state) { case ALSourceState.Playing: return; case ALSourceState.Paused: Resume(); return; } Prepare(); AL.SourcePlay(alSourceId); ALHelper.CheckError("Failed to play source."); Preparing = false; OggStreamer.Instance.AddStream(this); }
/// <summary> /// Called repeatedly, this method cleans up the state of the management lists. This method /// will also lock on the playingSourcesCollection. Sources that are stopped will be recycled /// using the RecycleSource method. /// </summary> public void Update() { if (!_bSoundAvailable) { //OK to ignore this here because the game can run without sound. return; } ALSourceState state; lock (playingSourcesCollection) { for (int i = playingSourcesCollection.Count - 1; i >= 0; --i) { int sourceId = playingSourcesCollection[i]; state = AL.GetSourceState(sourceId); ALHelper.CheckError("Failed to get source state."); if (state == ALSourceState.Stopped) { purgeMe.Add(sourceId); playingSourcesCollection.RemoveAt(i); } } } lock (purgeMe) { foreach (int sourceId in purgeMe) { AL.Source(sourceId, ALSourcei.Buffer, 0); ALHelper.CheckError("Failed to free source from buffer."); inUseSourcesCollection.Remove(sourceId); availableSourcesCollection.Add(sourceId); } purgeMe.Clear(); } }
void EnsureBuffersFilled() { while (!cancelled) { Thread.Sleep((int)(1000 / ((UpdateRate <= 0) ? 1 : UpdateRate))); if (cancelled) { break; } threadLocalStreams.Clear(); lock (iterationMutex) threadLocalStreams.AddRange(streams); foreach (var stream in threadLocalStreams) { lock (stream.prepareMutex) { lock (iterationMutex) if (!streams.Contains(stream)) { continue; } bool finished = false; int queued; AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersQueued, out queued); ALHelper.CheckError("Failed to fetch queued buffers."); int processed; AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersProcessed, out processed); ALHelper.CheckError("Failed to fetch processed buffers."); if (processed == 0 && queued == stream.BufferCount) { continue; } int[] tempBuffers; if (processed > 0) { tempBuffers = AL.SourceUnqueueBuffers(stream.alSourceId, processed); ALHelper.CheckError("Failed to unqueue buffers."); } else { tempBuffers = stream.alBufferIds.Skip(queued).ToArray(); } int bufferFilled = 0; for (int i = 0; i < tempBuffers.Length && !pendingFinish; i++) { finished |= FillBuffer(stream, tempBuffers[i]); bufferFilled++; if (finished) { if (stream.IsLooped) { stream.Close(); stream.Open(); } else { pendingFinish = true; } } } if (pendingFinish && queued == 0) { pendingFinish = false; lock (iterationMutex) streams.Remove(stream); if (stream.FinishedAction != null) { stream.FinishedAction.Invoke(); } } else if (!finished && bufferFilled > 0) // queue only successfully filled buffers { AL.SourceQueueBuffers(stream.alSourceId, bufferFilled, tempBuffers); ALHelper.CheckError("Failed to queue buffers."); } else if (!stream.IsLooped) { continue; } } lock (stream.stopMutex) { if (stream.Preparing) { continue; } lock (iterationMutex) if (!streams.Contains(stream)) { continue; } var state = AL.GetSourceState(stream.alSourceId); ALHelper.CheckError("Failed to get source state."); if (state == ALSourceState.Stopped) { AL.SourcePlay(stream.alSourceId); ALHelper.CheckError("Failed to play."); } } } } }
void StopPlayback() { AL.SourceStop(alSourceId); ALHelper.CheckError("Failed to stop source."); }
public void SeekToPosition(TimeSpan pos) { Reader.DecodedTime = pos; AL.SourceStop(alSourceId); ALHelper.CheckError("Failed to stop source."); }
private void PlatformResume() { AL.GetError(); AL.SourcePlay(SourceId); ALHelper.CheckError("Failed to play the source."); }
private void PlatformPause() { AL.GetError(); AL.SourcePause(SourceId); ALHelper.CheckError("Failed to pause the source."); }
public OALSoundBuffer() { AL.GenBuffers(1, out openALDataBuffer); ALHelper.CheckError("Failed to generate OpenAL data buffer."); }