示例#1
0
        protected override void WndProc(ref Message m)
        {
            var message = (WaveInterop.WaveMessage)m.Msg;

            switch (message)
            {
            case WaveInterop.WaveMessage.WaveOutDone:
            case WaveInterop.WaveMessage.WaveInData:
                IntPtr hOutputDevice = m.WParam;
                var    waveHeader    = new WaveHeader();
                Marshal.PtrToStructure(m.LParam, waveHeader);
                waveCallback(hOutputDevice, message, IntPtr.Zero, waveHeader, IntPtr.Zero);
                break;

            case WaveInterop.WaveMessage.WaveOutOpen:
            case WaveInterop.WaveMessage.WaveOutClose:
            case WaveInterop.WaveMessage.WaveInClose:
            case WaveInterop.WaveMessage.WaveInOpen:
                waveCallback(m.WParam, message, IntPtr.Zero, null, IntPtr.Zero);
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
示例#2
0
		/// <summary>
		/// creates a new wavebuffer
		/// </summary>
		/// <param name="waveInHandle">WaveIn device to write to</param>
		/// <param name="bufferSize">Buffer size in bytes</param>
		public WaveInBuffer(IntPtr waveInHandle, Int32 bufferSize)
		{
			this.bufferSize = bufferSize;
			buffer = new byte[bufferSize];
			hBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
			this.waveInHandle = waveInHandle;

			header = new WaveHeader();
			hHeader = GCHandle.Alloc(header);
			header.dataBuffer = hBuffer.AddrOfPinnedObject();
			header.bufferLength = bufferSize;
			header.loops = 1;
			hThis = GCHandle.Alloc(this);
			header.userData = (IntPtr) hThis;

			MmException.Try(WaveInterop.waveInPrepareHeader(waveInHandle, header, Marshal.SizeOf(header)), "waveInPrepareHeader");
			MmException.Try(WaveInterop.waveInAddBuffer(waveInHandle, header, Marshal.SizeOf(header)), "waveInAddBuffer");
		}
示例#3
0
		/// <summary>
		/// creates a new wavebuffer
		/// </summary>
		/// <param name="hWaveOut">WaveOut device to write to</param>
		/// <param name="bufferSize">Buffer size in bytes</param>
		/// <param name="bufferFillStream">Stream to provide more data</param>
		/// <param name="waveOutLock">Lock to protect WaveOut API's from being called on >1 thread</param>
		public WaveOutBuffer(IntPtr hWaveOut, Int32 bufferSize, IWaveProvider bufferFillStream, object waveOutLock)
		{
			this.bufferSize = bufferSize;
			buffer = new byte[bufferSize];
			hBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
			this.hWaveOut = hWaveOut;
			waveStream = bufferFillStream;
			this.waveOutLock = waveOutLock;

			header = new WaveHeader();
			hHeader = GCHandle.Alloc(header);
			header.dataBuffer = hBuffer.AddrOfPinnedObject();
			header.bufferLength = bufferSize;
			header.loops = 1;
			hThis = GCHandle.Alloc(this);
			header.userData = (IntPtr) hThis;
			lock (waveOutLock)
			{
				MmException.Try(WaveInterop.waveOutPrepareHeader(hWaveOut, header, Marshal.SizeOf(header)), "waveOutPrepareHeader");
			}
		}
示例#4
0
		protected override void WndProc(ref Message m)
		{
			var message = (WaveInterop.WaveMessage) m.Msg;

			switch (message)
			{
				case WaveInterop.WaveMessage.WaveOutDone:
				case WaveInterop.WaveMessage.WaveInData:
					IntPtr hOutputDevice = m.WParam;
					var waveHeader = new WaveHeader();
					Marshal.PtrToStructure(m.LParam, waveHeader);
					waveCallback(hOutputDevice, message, IntPtr.Zero, waveHeader, IntPtr.Zero);
					break;
				case WaveInterop.WaveMessage.WaveOutOpen:
				case WaveInterop.WaveMessage.WaveOutClose:
				case WaveInterop.WaveMessage.WaveInClose:
				case WaveInterop.WaveMessage.WaveInOpen:
					waveCallback(m.WParam, message, IntPtr.Zero, null, IntPtr.Zero);
					break;
				default:
					base.WndProc(ref m);
					break;
			}
		}
示例#5
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader,
                              IntPtr reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                var hBuffer = (GCHandle)waveHeader.userData;
                var buffer  = (WaveInBuffer)hBuffer.Target;

                if (DataAvailable != null)
                {
                    DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
                }
                if (recording)
                {
                    buffer.Reuse();
                }
                else
                {
                    if (RecordingStopped != null)
                    {
                        RecordingStopped(this, EventArgs.Empty);
                    }
                }
            }
        }
示例#6
0
 public static extern MmResult waveOutWrite(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
示例#7
0
 public static extern MmResult waveOutUnprepareHeader(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
示例#8
0
 public static extern MmResult waveInPrepareHeader(IntPtr hWaveIn, WaveHeader lpWaveInHdr, int uSize);
示例#9
0
 public static extern MmResult waveInAddBuffer(IntPtr hWaveIn, WaveHeader pwh, int cbwh);
示例#10
0
		public static extern MmResult waveOutWrite(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
示例#11
0
		public static extern MmResult waveOutUnprepareHeader(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
示例#12
0
		public static extern MmResult waveInPrepareHeader(IntPtr hWaveIn, WaveHeader lpWaveInHdr, int uSize);
示例#13
0
		public static extern MmResult waveInAddBuffer(IntPtr hWaveIn, WaveHeader pwh, int cbwh);
示例#14
0
		// made non-static so that playing can be stopped here
		private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwUser, WaveHeader wavhdr,
		                      IntPtr dwReserved)
		{
			if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
			{
				// check that we're not here through pressing stop
				var hBuffer = (GCHandle) wavhdr.userData;
				var buffer = (WaveOutBuffer) hBuffer.Target;

				lock (actionQueue)
				{
					actionQueue.Enqueue(new WaveOutAction(WaveOutFunction.BufferDone, buffer));
					workAvailable.Set();
				}

				// n.b. this was wrapped in an exception handler, but bug should be fixed now
			}
		}
示例#15
0
		/// <summary>
		/// Called when we get a new buffer of recorded data
		/// </summary>
		private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader,
		                      IntPtr reserved)
		{
			if (message == WaveInterop.WaveMessage.WaveInData)
			{
				var hBuffer = (GCHandle) waveHeader.userData;
				var buffer = (WaveInBuffer) hBuffer.Target;

				length += buffer.BytesRecorded;
				if (DataAvailable != null)
				{
					DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
				}
				if (recording)
				{
					buffer.Reuse();
				}
				else
				{
					if (RecordingStopped != null)
					{
						RecordingStopped(this, EventArgs.Empty);
					}
				}
			}
		}
示例#16
0
		// made non-static so that playing can be stopped here
		private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr,
		                      IntPtr dwReserved)
		{
			if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
			{
				var hBuffer = (GCHandle) wavhdr.userData;
				var buffer = (WaveOutBuffer) hBuffer.Target;
				// check that we're not here through pressing stop
				if (PlaybackState == PlaybackState.Playing)
				{
					if (!buffer.OnDone())
					{
						playbackState = PlaybackState.Stopped;
						RaisePlaybackStoppedEvent();
					}
				}

				// n.b. this was wrapped in an exception handler, but bug should be fixed now
			}
		}