Esempio n. 1
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();
        }
Esempio n. 2
0
        private void Init()
        {
            _WaveFormat = new WaveFormatEx();

            SetFormatValues();
        }
Esempio n. 3
0
 public static extern int waveOutOpen(out IntPtr device, int deviceID, ref WaveFormatEx format, WaveOutProcDelegate callback, int instance, int flags);
Esempio n. 4
0
//
//		private Stream _DataStream;
//
//		public WavePlayer( int device, Stream s )
//		{
//			if ( s == null )
//				throw new ArgumentNullException( "s" );
//
//			_DataStream = s;
//
//		}

        public WavePlayer(int device,
                          int bufferDataSize, int bufferCount,
                          WaveFormat format,
                          WaveBufferEmptyHandler bufferEmptyHandler)
        {
            if (bufferDataSize <= 0)
            {
                throw new ArgumentOutOfRangeException("bufferDataSize", bufferDataSize, "bufferDataSize must be greater than 0.");
            }

            this._BufferDataSize = bufferDataSize;

            if (bufferCount <= 0)
            {
                throw new ArgumentOutOfRangeException("bufferCount", bufferCount, "bufferCount must be greater than 0.");
            }

            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            WaveFormatEx formatEx = format.GetFormat();

            this._BufferCount = 2;

            if (bufferEmptyHandler == null)
            {
                throw new ArgumentNullException("bufferEmptyHandler");
            }

            this._BufferEmptyHandler = bufferEmptyHandler;


            int result = WaveFormNative.waveOutOpen(out _Device,
                                                    device,
                                                    ref formatEx,
                                                    _CallBack,
                                                    0,
                                                    (int)DeviceOpenFlags.CallbackFunction);

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

            AllocateBuffers();

            _IsPlaying = true;

            FillBuffer(_Buffers[0]);

            _Buffers[0].Play();

//			FillBuffers();
//
//			_FillThread = new Thread( new ThreadStart( FillBufferLoop ) );
//			_FillThread.Start();
//
//			_RootBuffer.Play();
            _PlayThread          = new Thread(new ThreadStart(PlayLoop));
            _PlayThread.Priority = ThreadPriority.Highest;
            _PlayThread.Start();
        }