Exemplo n.º 1
0
        public WaveOutDeviceCapabilities(int device)
        {
            this._Capabilities = new WAVEOUTCAPS();

            int result = waveOutGetDevCaps(device, this._Capabilities, Marshal.SizeOf(this._Capabilities));

            if (result != WaveError.MMSYSERR_NOERROR)
            {
                throw new SoundCoreException(WaveError.GetMessage(result), result);
            }
        }
Exemplo n.º 2
0
        public virtual void Play()
        {
            this._WaitForCompletion.Reset();

//			this._PlayEvent.WaitOne();
//			this._PlayEvent.Reset();
            this._IsPlaying = true;

            int result = WaveFormNative.waveOutWrite(this._DeviceHandle, ref this._Header, Marshal.SizeOf(this._Header));

            if (result != WaveError.MMSYSERR_NOERROR)
            {
                throw new SoundCoreException(WaveError.GetMessage(result), result);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates and prepares a WaveOutBuffer.
        /// </summary>
        /// <param name="device">Handle to WaveOut device to prepare the buffer for</param>
        /// <param name="size">Size of the buffer, in bytes</param>
        public WaveOutBuffer(WavePlayer player, IntPtr device, int size)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            _Player = player;

            if (device == IntPtr.Zero)
            {
                throw new ArgumentException("Device must be a a valid pointer to a wave out device.", "device");
            }

            if (size < 1)
            {
                throw new ArgumentOutOfRangeException("size", size, "Size must be greater than zero.");
            }

            _Length       = size;
            _DeviceHandle = device;

            // Allocate memory for the buffer, and set up a GCHandle pointed to it.
            byte[] buffer = new byte[Length];
            _DataHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            // Create the header and a GC handle pointed to it.
            _Header       = new WaveHeader();
            _HeaderHandle = GCHandle.Alloc(_Header, GCHandleType.Pinned);

            _Header.Data         = this.Data;
            _Header.BufferLength = Length;

            _Header.UserData = (IntPtr)GCHandle.Alloc(this);
            _Header.Loops    = 0;
            _Header.Flags    = 0;

            int result = WaveFormNative.waveOutPrepareHeader(_DeviceHandle,
                                                             ref _Header, Marshal.SizeOf(_Header));

            if (result != WaveError.MMSYSERR_NOERROR)
            {
                throw new SoundCoreException(WaveError.GetMessage(result), result);
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }