Пример #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);
             }
         }
         catch (Exception ex)
         {
             LogManage.WriteLog(this.GetType(), ex);
         }
     }
Пример #2
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(1000);
             m_DoneProc = null;
             FreeBuffers();
             if (m_WaveIn != IntPtr.Zero)
             {
                 WaveNative.waveInClose(m_WaveIn);
             }
         }
         finally
         {
             m_Thread = null;
             m_WaveIn = IntPtr.Zero;
         }
     }
     GC.SuppressFinalize(this);
 }
Пример #3
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();
        }
Пример #4
0
        public void Dispose()
        {
            if (m_Thread != null)
                try
                {
                    m_Finished = true;

                    WaitForAllBuffers();
                    if (m_WaveIn != IntPtr.Zero)
                    {
                        WaveNative.waveInReset(m_WaveIn);
                    }

                    m_Thread.Join(JOIN_TIMEOUT);
                    m_DoneProc = null;
                    FreeBuffers();
                    if (m_WaveIn != IntPtr.Zero)
                    {
                        WaveNative.waveInClose(m_WaveIn);
                    }
                }
                finally
                {
                    m_Thread = null;
                    m_WaveIn = IntPtr.Zero;
                }
            GC.SuppressFinalize(this);
        }
Пример #5
0
 public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc, Action <bool> callBack)
 {
     try
     {
         m_DoneProc = doneProc;
         int error = WaveNative.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION);
         WaveInHelper.Try(error);
         AllocateBuffers(bufferSize, bufferCount);
         for (int i = 0; i < bufferCount; i++)
         {
             SelectNextBuffer();
             m_CurrentBuffer.Record();
         }
         error = WaveNative.waveInStart(m_WaveIn);
         WaveInHelper.Try(error);
         m_Thread = new Thread(new ThreadStart(ThreadProc));
         m_Thread.Start();
         if (callBack != null)
         {
             callBack(true);
         }
     }
     catch (Exception)
     {
         if (callBack != null)
         {
             callBack(false);
         }
     }
 }
Пример #6
0
        public void Dispose()
        {
            if (recordingThread != null)
                try
                {
                    finished = true;
                    if (recordingThread.IsAlive)
                        recordingThread.Join();

                    WaitForAllBuffers();
                    doneProc = null;
                    FreeBuffers();

                    if (waveIn != IntPtr.Zero)
                    {
                        Winmm.waveInReset(waveIn);
                        Winmm.waveInClose(waveIn);
                    }
                }
                finally
                {
                    recordingThread = null;
                    waveIn = IntPtr.Zero;
                }
            GC.SuppressFinalize(this);
        }
Пример #7
0
        /// <summary>Stop recording and reset</summary>
        /// <returns>MMSYSERR</returns>
        public MMSYSERR Stop()
        {
            MMSYSERR mmr = MMSYSERR.ERROR;

            try
            {
                _bFinished = true;
                if (_pWaveIn != IntPtr.Zero)
                {
                    waveInReset(_pWaveIn);
                }
                if (_cThread != null)
                {
                    _cThread.Abort();
                }
                _eDoneProc = null;
                FreeBuffers();
                if (_pWaveIn != IntPtr.Zero)
                {
                    mmr = waveInClose(_pWaveIn);
                }
                else
                {
                    mmr = MMSYSERR.NOERROR;
                }
            }
            finally
            {
                _cThread  = null;
                _pWaveIn  = IntPtr.Zero;
                Recording = false;
            }
            return(mmr);
        }
Пример #8
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();
 }
Пример #9
0
 public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc)
 {
     this.doneProc = doneProc;
     WaveInHelper.Try(Winmm.waveInOpen(out waveIn, device, format, bufferProc, 0, Winmm.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     for (var i = 0; i < bufferCount; i++)
     {
         SelectNextBuffer();
         currentBuffer.Record();
     }
     WaveInHelper.Try(Winmm.waveInStart(waveIn));
     recordingThread = new Thread(ThreadProc);
     recordingThread.Start();
 }
Пример #10
0
 /// <summary>Initialze class and set defaults</summary>
 /// <param name="device">device id</param>
 /// <param name="format">WAVEFORMATEX format description</param>
 /// <param name="doneProc">data callback</param>
 public WaveInRecorder(int device, ref WAVEFORMATEX format, BufferDoneEventHandler doneProc)
 {
     _eDoneProc             = doneProc;
     format                 = WaveFormat(format.nSamplesPerSec, format.wBitsPerSample, format.nChannels);
     _tWaveFormat           = format;
     this.Device            = device;
     this.BufferSize        = 4096;
     this.BufferCount       = 4;
     this.Channels          = _tWaveFormat.nChannels;
     this.BitsPerSample     = _tWaveFormat.wBitsPerSample;
     this.SamplesPerSecond  = _tWaveFormat.nSamplesPerSec;
     this.AvgBytesPerSecond = _tWaveFormat.nAvgBytesPerSec;
     this.Format            = _tWaveFormat.wFormatTag;
 }
Пример #11
0
        public WaveInRecorder(int device, WaveFormat format, int bufferSize, BufferDoneEventHandler doneProc)
        {
            m_DoneProc = doneProc;
            WaveInRecorder.ThrowOnError(WaveNative.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));

            buffer1 = new WaveInBuffer(m_WaveIn, bufferSize);
            buffer2 = new WaveInBuffer(m_WaveIn, bufferSize);

            buffer1.Record();
            buffer2.Record();

            m_CurrentBuffer = buffer1;

            WaveInRecorder.ThrowOnError(WaveNative.waveInStart(m_WaveIn));
            m_Thread = new Thread(new ThreadStart(ThreadProc));
            m_Thread.Start();
        }
Пример #12
0
        public void Close()
        {
            m_Finished = true;
            WaveInRecorder.ThrowOnError(WaveNative.waveInReset(m_WaveIn));

            m_Thread.Join();
            m_Thread   = null;
            m_DoneProc = null;

            buffer1.WaitFor();
            buffer2.WaitFor();

            buffer1.Close();
            buffer2.Close();

            WaveInRecorder.ThrowOnError(WaveNative.waveInClose(m_WaveIn));
            m_WaveIn = IntPtr.Zero;
        }
Пример #13
0
 public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount,
                       BufferDoneEventHandler doneProc)
 {
     _mDoneProc = doneProc;
     WaveInHelper.Try(WaveNative.waveInOpen(out _mWaveIn, device, format, _mBufferProc, 0,
                                            WaveNative.CallbackFunction));
     AllocateBuffers(bufferSize, bufferCount);
     for (var i = 0; i < bufferCount; i++)
     {
         SelectNextBuffer();
         _mCurrentBuffer.Record();
     }
     WaveInHelper.Try(WaveNative.waveInStart(_mWaveIn));
     _mThread = new Thread(ThreadProc)
     {
         IsBackground = true
     };
     _mThread.Start();
 }
Пример #14
0
 public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc)
 {
     try
     {
         EncoderWorking = false;
         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.Name = "WaveInRecorder Thread :  ThreadProc()";
         m_Thread.Start();
         EncoderWorking = true;
     }
     catch (Exception)
     {
     }
 }
Пример #15
0
        public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc)
        {
            try
            {
                EncoderWorking = false;
                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.Name = "WaveInRecorder Thread :  ThreadProc()";
                m_Thread.Start();
                EncoderWorking = true;
            }
            catch(Exception )
            {

            }
        }
        /// <summary>Stop recording and reset.</summary>
        /// <returns>MMSYSERR.</returns>
        public MMSYSERR Stop()
        {
            MMSYSERR mmr = MMSYSERR.ERROR;
            try
            {
                _isFinished = true;

                if (_pWaveIn != IntPtr.Zero)
                    waveInReset(_pWaveIn); // system function

                if (_thread != null)
                    _thread.Abort();

                _eDoneProc = null;
                _FreeBuffers();

                if (_pWaveIn != IntPtr.Zero)
                    mmr = waveInClose(_pWaveIn); // system function
                else
                    mmr = MMSYSERR.NOERROR;
            }
            finally
            {
                _thread = null;
                _pWaveIn = IntPtr.Zero;
            }
            return mmr;
        }
Пример #17
0
 public WindowsWaveInRecorder(int device, Windows.WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc)
 {
     this.doneProc = doneProc;
     Windows.FailOnMMError(Windows.waveInOpen(out waveInPtr, device, format, bufferProc, 0, Windows.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     for (int i = 0; i < bufferCount; i++)
     {
         SelectNextBuffer();
         currentBuffer.Record();
     }
     Windows.FailOnMMError(Windows.waveInStart(waveInPtr));
     thread = new Thread(new ThreadStart(ThreadProc));
     thread.Start();
 }
 /// <summary>Initialze class and set defaults.</summary>
 /// <param name="device">Current device id.</param>
 /// <param name="doneProc">data callback</param>
 /// <param name="format">WAVEFORMATEX format description</param>
 public WaveInRecorder(int device, BufferDoneEventHandler doneProc, WaveFormatEx format)
 {
     _device = device;
     _eDoneProc = doneProc;
     _waveFormat = format;
 }
Пример #19
0
 /// <summary>Initialze class and set defaults.</summary>
 /// <param name="device">Current device id.</param>
 /// <param name="doneProc">data callback</param>
 /// <param name="format">WAVEFORMATEX format description</param>
 public WaveInRecorder(int device, BufferDoneEventHandler doneProc, WaveFormatEx format)
 {
     _device     = device;
     _eDoneProc  = doneProc;
     _waveFormat = format;
 }