Ejemplo n.º 1
0
//
//		private void FillBufferLoop()
//		{
//			WaveOutBuffer current = _RootBuffer;
//
//			while( IsPlaying )
//			{
//				// Wait until buffer has been read
//				current.WaitUntilEmpty();
//
//				// Fill the buffer
//				FillBuffer( current );
//
//				// Move to next buffer
//				current = current.NextBuffer;
//			}
//		}

        private void PlayLoop()
        {
            int index = 0;

            WaveOutBuffer buffer  = _Buffers[index];
            WaveOutBuffer playing = null;

            FillBuffer(buffer);

            while (IsPlaying)
            {
                buffer.Play();

                playing = buffer;

                index  = ++index % BufferCount;
                buffer = _Buffers[index];
                FillBuffer(buffer);

                playing.WaitUntilCompleted();
//
//				WaveOutBuffer buffer = _Buffers[index];
//				FillBuffer( buffer );
//
//
//				buffer.Play();
//				buffer.WaitUntilCompleted();
//
//				current = current.NextBuffer;
            }

            this._FinishEvent.Set();
        }
Ejemplo n.º 2
0
        public void Play()
        {
#if DEBUG
            this._FillCount = 0;
#endif
            if (_DataStream != null)
            {
                _DataStream.Position = _StartPosition;
            }

            WaveFormatEx format = Format.GetFormat();

            int result = WaveFormNative.waveOutOpen(out _DeviceHandle, Device, ref format, _CallBack, 0,
                                                    (int)DeviceOpenFlags.CallbackFunction);

            if (result != WaveError.MMSYSERR_NOERROR)
            {
                throw new SoundCoreException(WaveError.GetMessage(result), result);
            }

            _IsPlaying = true;

            AllocateBuffers();

            // Perform Initial fill
            WaveOutBuffer current = _RootBuffer;
            do
            {
                FillBuffer(current);
                current.BufferFilled();

                current = current.NextBuffer;
            } while (current != _RootBuffer);

            _RootBuffer.Play();
            //
            //			_FillThread = new Thread( new ThreadStart( FillProc ) );
            ////			_FillThread.Priority = ThreadPriority.Highest;
            //			_FillThread.Start();
            //
            //			_PlayThread = new Thread( new ThreadStart( PlayProc ) );
            //			_PlayThread.Start();
        }