/// <summary>
        /// Callback function for the outputstream.
        /// </summary>
        /// <param name="streamHandle">Bass stream handle that requests sample data.</param>
        /// <param name="buffer">Buffer to write the sampledata in.</param>
        /// <param name="requestedBytes">Requested number of bytes.</param>
        /// <param name="userData"></param>
        /// <returns>Number of bytes read.</returns>
        private int OutputStreamWriteProc(int streamHandle, IntPtr buffer, int requestedBytes, IntPtr userData)
        {
            if (_deviceState == DeviceState.Stopped)
            {
                return((int)BASSStreamProc.BASS_STREAMPROC_END);
            }
            if (_outputStreamEnded)
            {
                return((int)BASSStreamProc.BASS_STREAMPROC_END);
            }
            int read = _inputStream.Read(buffer, requestedBytes);

            if (read == -1)
            {
                // We're done!

                // Play silence until playback has stopped to avoid any buffer underruns.
                read = _silence.Write(buffer, requestedBytes);

                // Set a flag so we call HandleOutputStreamEnded() only once.
                _outputStreamEnded = true;

                // Our input stream is finished, wait for device to end playback
                HandleOutputStreamAboutToEnd();
            }
            return(read);
        }
        protected virtual int WriteOutputStream(IntPtr buffer, int requestedBytes)
        {
            if (_deviceState == DeviceState.Stopped || _outputStreamEnded)
            {
                return((int)BASSStreamProc.BASS_STREAMPROC_END);
            }

            int read = ReadStream.Read(buffer, requestedBytes);

            if (read != -1)
            {
                return(read);
            }

            // We're done!
            // Play silence until playback has stopped to avoid any buffer underruns.
            read = _silence.Write(buffer, requestedBytes);

            // Set a flag so we call HandleOutputStreamEnded() only once.
            _outputStreamEnded = true;

            // Our input stream is finished, wait for device to end playback
            HandleOutputStreamAboutToEnd();
            return(read);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Callback function for the visualization stream.
        /// </summary>
        /// <param name="streamHandle">Bass stream handle that requests sample data.</param>
        /// <param name="buffer">Buffer to write the sampledata to.</param>
        /// <param name="requestedBytes">Requested number of bytes.</param>
        /// <param name="userData">Not used.</param>
        /// <returns>Number of bytes read.</returns>
        private int VizRawStreamWriteProc(int streamHandle, IntPtr buffer, int requestedBytes, IntPtr userData)
        {
            if (buffer == IntPtr.Zero)
            {
                return(0);
            }

            if (_controller.Player.ExternalState == PlayerState.Active)
            {
                int read = _buffer.Peek(buffer, requestedBytes / BassConstants.FloatBytes, _vizReadOffsetBytes);
                return((read == 0 && _streamEnded) ? (int)BASSStreamProc.BASS_STREAMPROC_END : read *BassConstants.FloatBytes);
            }
            return(_silence.Write(buffer, requestedBytes));
        }