Пример #1
0
        internal override void Begin(byte[] wfx)
        {
            if (_deviceOpen)
            {
                throw new InvalidOperationException();
            }
            WAVEFORMATEX.AvgBytesPerSec(wfx, out _nAvgBytesPerSec, out _blockAlign);
            MMSYSERR mMSYSERR;

            lock (_noWriteOutLock)
            {
                mMSYSERR = SafeNativeMethods.waveOutOpen(ref _hwo, _curDevice, wfx, _delegate, IntPtr.Zero, 196608u);
                if (_fPaused && mMSYSERR == MMSYSERR.NOERROR)
                {
                    mMSYSERR = SafeNativeMethods.waveOutPause(_hwo);
                }
                _aborted    = false;
                _deviceOpen = true;
            }
            if (mMSYSERR != 0)
            {
                throw new AudioException(mMSYSERR);
            }
            _bytesWritten = 0;
            _evt.Set();
        }
Пример #2
0
        /// <summary>
        /// Begin to play
        /// </summary>
        internal override void Begin(byte[] wfx)
        {
            if (_deviceOpen)
            {
                System.Diagnostics.Debug.Assert(false);
                throw new InvalidOperationException();
            }

            // Get the alignments values
            WAVEFORMATEX.AvgBytesPerSec(wfx, out _nAvgBytesPerSec, out _blockAlign);

            MMSYSERR result;

            lock (_noWriteOutLock)
            {
                result = SafeNativeMethods.waveOutOpen(ref _hwo, _curDevice, wfx, _delegate, IntPtr.Zero, SafeNativeMethods.CALLBACK_FUNCTION);

                if (_fPaused && result == MMSYSERR.NOERROR)
                {
                    result = SafeNativeMethods.waveOutPause(_hwo);
                }
                // set the flags
                _aborted    = false;
                _deviceOpen = true;
            }

            if (result != MMSYSERR.NOERROR)
            {
                throw new AudioException(result);
            }

            // Reset the counter for the number of bytes written so far
            _bytesWritten = 0;

            // Nothing in the queue
            _evt.Set();
        }