Exemplo n.º 1
0
 public void Dispose()
 {
     if (m_Thread != null)
     {
         try
         {
             m_Finished = true;
             if (m_WaveIn != IntPtr.Zero)
             {
                 WaveNative.waveInReset(m_WaveIn);
             }
             WaitForAllBuffers();
             m_Thread.Join();
             m_DoneProc = null;
             FreeBuffers();
             if (m_WaveIn != IntPtr.Zero)
             {
                 WaveNative.waveInClose(m_WaveIn);
             }
         }
         finally
         {
             m_Thread = null;
             m_WaveIn = IntPtr.Zero;
         }
     }
     GC.SuppressFinalize(this);
 }
Exemplo n.º 2
0
 public bool Record()
 {
     lock (this)
     {
         m_RecordEvent.Reset();
         m_Recording = WaveNative.waveInAddBuffer(m_WaveIn, ref m_Header, Marshal.SizeOf(m_Header)) == WaveNative.MMSYSERR_NOERROR;
         return(m_Recording);
     }
 }
Exemplo n.º 3
0
        public WaveInBuffer(IntPtr waveInHandle, int size)
        {
            m_WaveIn = waveInHandle;

            m_HeaderHandle          = GCHandle.Alloc(m_Header, GCHandleType.Pinned);
            m_Header.dwUser         = (IntPtr)GCHandle.Alloc(this);
            m_HeaderData            = new byte[size];
            m_HeaderDataHandle      = GCHandle.Alloc(m_HeaderData, GCHandleType.Pinned);
            m_Header.lpData         = m_HeaderDataHandle.AddrOfPinnedObject();
            m_Header.dwBufferLength = size;
            WaveInHelper.Try(WaveNative.waveInPrepareHeader(m_WaveIn, ref m_Header, Marshal.SizeOf(m_Header)));
        }
Exemplo n.º 4
0
 public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc)
 {
     m_DoneProc = doneProc;
     WaveInHelper.Try(WaveNative.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     for (int i = 0; i < bufferCount; i++)
     {
         SelectNextBuffer();
         m_CurrentBuffer.Record();
     }
     WaveInHelper.Try(WaveNative.waveInStart(m_WaveIn));
     m_Thread = new Thread(new ThreadStart(ThreadProc));
     m_Thread.Start();
 }
Exemplo n.º 5
0
 public void Dispose()
 {
     if (m_Header.lpData != IntPtr.Zero)
     {
         WaveNative.waveInUnprepareHeader(m_WaveIn, ref m_Header, Marshal.SizeOf(m_Header));
         m_HeaderHandle.Free();
         m_Header.lpData = IntPtr.Zero;
     }
     m_RecordEvent.Close();
     if (m_HeaderDataHandle.IsAllocated)
     {
         m_HeaderDataHandle.Free();
     }
     GC.SuppressFinalize(this);
 }
Exemplo n.º 6
0
 internal static void WaveInProc(IntPtr hdrvr, int uMsg, int dwUser, ref WaveNative.WaveHdr wavhdr, int dwParam2)
 {
     if (uMsg == WaveNative.MM_WIM_DATA)
     {
         try
         {
             GCHandle h = (GCHandle)wavhdr.dwUser;
             WaveInBuffer buf = (WaveInBuffer)h.Target;
             buf.OnCompleted();
         }
         catch
         {
         }
     }
 }