/// <summary> /// Restarts streaming from the beginning. /// </summary> protected virtual void RestartInternal() { ReadyToPlay.TrySetResult(false); ReadyToPlay = new TaskCompletionSource <bool>(); readyToPlay = false; prebufferedCount = 0; PrepareInternal(); }
/// <summary> /// Restarts streaming from the beginning. /// </summary> protected void Restart() { ReadyToPlay.TrySetResult(false); ReadyToPlay = new TaskCompletionSource <bool>(); Ended.TrySetResult(false); Ended = new TaskCompletionSource <bool>(); readyToPlay = false; prebufferedCount = 0; }
/// <summary> /// If CanFillis true with this method you can fill the next free buffer /// </summary> /// <param name="pcm">The pointer to PCM data</param> /// <param name="bufferSize">The full size in bytes of PCM data</param> /// <param name="type">If this buffer is the last buffer of the stream set to true, if not false</param> protected void FillBuffer(IntPtr pcm, int bufferSize, AudioLayer.BufferType type) { var buffer = freeBuffers.Dequeue(); AudioLayer.SourceQueueBuffer(SoundInstance.Source, buffer, pcm, bufferSize, type); if (readyToPlay) { return; } prebufferedCount++; if (prebufferedCount < prebufferedTarget) { return; } readyToPlay = true; ReadyToPlay.TrySetResult(true); }
/// <summary> /// If CanFillis true with this method you can fill the next free buffer /// </summary> /// <param name="pcm">The pointer to PCM data</param> /// <param name="bufferSize">The full size in bytes of PCM data</param> /// <param name="endOfStream">If this buffer is the last buffer of the stream set to true, if not false</param> protected void FillBuffer(IntPtr pcm, int bufferSize, bool endOfStream) { var buffer = freeBuffers.Dequeue(); AudioLayer.SourceQueueBuffer(SoundInstance.Source, buffer, pcm, bufferSize, endOfStream); if (readyToPlay) { return; } prebufferedCount++; if (prebufferedCount > 1) { return; } readyToPlay = true; ReadyToPlay.TrySetResult(true); }
/// <summary> /// If CanFillis true with this method you can fill the next free buffer /// </summary> /// <param name="pcm">The array containing PCM data</param> /// <param name="bufferSize">The full size in bytes of PCM data</param> /// <param name="type">If this buffer is the last buffer of the stream set to true, if not false</param> protected unsafe void FillBuffer(short[] pcm, int bufferSize, AudioLayer.BufferType type) { var buffer = freeBuffers.Dequeue(); fixed(short *pcmBuffer = pcm) AudioLayer.SourceQueueBuffer(SoundInstance.Source, buffer, new IntPtr(pcmBuffer), bufferSize, type); if (readyToPlay) { return; } prebufferedCount++; if (prebufferedCount < prebufferedTarget) { return; } readyToPlay = true; ReadyToPlay.TrySetResult(true); }
/// <summary> /// If CanFillis true with this method you can fill the next free buffer /// </summary> /// <param name="pcm">The pointer to PCM data</param> /// <param name="bufferSize">The full size in bytes of PCM data</param> /// <param name="type">If this buffer is the last buffer of the stream set to true, if not false</param> protected void FillBuffer(IntPtr pcm, int bufferSize, AudioLayer.BufferType type) { if (bufferSize > nativeBufferSizeBytes) { Logger.Error("Provided buffer size is bigger than native buffer. Data will be cut."); bufferSize = nativeBufferSizeBytes; } var buffer = freeBuffers.Dequeue(); AudioLayer.SourceQueueBuffer(SoundInstance.Source, buffer, pcm, bufferSize, type); if (readyToPlay) { return; } prebufferedCount++; if (prebufferedCount < prebufferedTarget) { return; } readyToPlay = true; ReadyToPlay.TrySetResult(true); }