Пример #1
0
 public void Dispose()
 {
     if (_mThread != null)
     {
         try
         {
             _mFinished = true;
             if (_mWaveIn != IntPtr.Zero)
             {
                 WaveNative.waveInReset(_mWaveIn);
             }
             WaitForAllBuffers();
             _mThread.Join();
             _mDoneProc = null;
             FreeBuffers();
             if (_mWaveIn != IntPtr.Zero)
             {
                 WaveNative.waveInClose(_mWaveIn);
             }
         }
         finally
         {
             _mThread = null;
             _mWaveIn = IntPtr.Zero;
         }
     }
     GC.SuppressFinalize(this);
 }
Пример #2
0
 public bool Record()
 {
     lock (this)
     {
         m_RecordEvent.Reset();
         _mRecording = WaveNative.waveInAddBuffer(m_WaveIn, ref _mHeader, Marshal.SizeOf(_mHeader)) ==
                       WaveNative.MmsyserrNoerror;
         return(_mRecording);
     }
 }
Пример #3
0
 public bool Play()
 {
     lock (this)
     {
         m_PlayEvent.Reset();
         _mPlaying = WaveNative.waveOutWrite(m_WaveOut, ref _mHeader, Marshal.SizeOf(_mHeader)) ==
                     WaveNative.MmsyserrNoerror;
         return(_mPlaying);
     }
 }
Пример #4
0
        public WaveInBuffer(IntPtr waveInHandle, int size)
        {
            m_WaveIn = waveInHandle;

            _mHeaderHandle          = GCHandle.Alloc(_mHeader, GCHandleType.Pinned);
            _mHeader.dwUser         = (IntPtr)GCHandle.Alloc(this);
            _mHeaderData            = new byte[size];
            _mHeaderDataHandle      = GCHandle.Alloc(_mHeaderData, GCHandleType.Pinned);
            _mHeader.lpData         = _mHeaderDataHandle.AddrOfPinnedObject();
            _mHeader.dwBufferLength = size;
            WaveInHelper.Try(WaveNative.waveInPrepareHeader(m_WaveIn, ref _mHeader, Marshal.SizeOf(_mHeader)));
        }
Пример #5
0
 public WaveOutPlayer(int device, WaveFormat format, int bufferSize, int bufferCount,
                      BufferFillEventHandler fillProc)
 {
     _mZero     = format.wBitsPerSample == 8 ? (byte)128 : (byte)0;
     _mFillProc = fillProc;
     WaveOutHelper.Try(WaveNative.waveOutOpen(out _mWaveOut, device, format, m_BufferProc, 0,
                                              WaveNative.CallbackFunction));
     AllocateBuffers(bufferSize, bufferCount);
     _mThread = new Thread(ThreadProc)
     {
         IsBackground = true
     };
     _mThread.Start();
 }
Пример #6
0
 public void Dispose()
 {
     if (_mHeader.lpData != IntPtr.Zero)
     {
         WaveNative.waveInUnprepareHeader(m_WaveIn, ref _mHeader, Marshal.SizeOf(_mHeader));
         _mHeaderHandle.Free();
         _mHeader.lpData = IntPtr.Zero;
     }
     m_RecordEvent.Close();
     if (_mHeaderDataHandle.IsAllocated)
     {
         _mHeaderDataHandle.Free();
     }
     GC.SuppressFinalize(this);
 }
Пример #7
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();
 }