示例#1
0
        /// <summary>
        /// Releases any buffers that have been fully written to the output device
        /// </summary>
        /// <param name="bytesRead">The amount of bytes written in the last device write</param>
        private void UpdateReleasedBuffers(int bytesRead)
        {
            bool bufferReleased = false;

            while (bytesRead > 0)
            {
                if (m_ReservedBuffers.TryPeek(out SoundIoBuffer buffer))
                {
                    if (buffer.Length > bytesRead)
                    {
                        buffer.Length -= bytesRead;
                        bytesRead      = 0;
                    }
                    else
                    {
                        bufferReleased = true;
                        bytesRead     -= buffer.Length;

                        m_ReservedBuffers.TryDequeue(out buffer);
                        ReleasedBuffers.Enqueue(buffer.Tag);
                    }
                }
            }

            if (bufferReleased)
            {
                OnBufferReleased();
            }
        }
示例#2
0
        /// <summary>
        /// Closes the <see cref="SoundIoAudioTrack"/>
        /// </summary>
        public void Close()
        {
            if (AudioStream != null)
            {
                AudioStream.Pause(true);
                AudioStream.Dispose();
            }

            m_Buffer.Clear();
            OnBufferReleased();
            ReleasedBuffers.Clear();

            State          = PlaybackState.Stopped;
            AudioStream    = null;
            BufferReleased = null;
        }
示例#3
0
        /// <summary>
        /// Flush all track buffers
        /// </summary>
        public bool FlushBuffers()
        {
            m_Buffer.Clear();

            if (m_ReservedBuffers.Count > 0)
            {
                foreach (var buffer in m_ReservedBuffers)
                {
                    ReleasedBuffers.Enqueue(buffer.Tag);
                }

                OnBufferReleased();

                return(true);
            }

            return(false);
        }