Пример #1
0
 public void SetVolume(int iVolumeLevel)
 {
     lock (this)
     {
         WaveNative.waveOutSetVolume(m_WaveOut, iVolumeLevel * 6550);
     }
 }
Пример #2
0
 public void Close()
 {
     WaveInRecorder.ThrowOnError(WaveNative.waveInUnprepareHeader(m_WaveIn, ref m_Header, Marshal.SizeOf(m_Header)));
     m_HeaderHandle.Free();
     m_Header.lpData = IntPtr.Zero;
     m_HeaderDataHandle.Free();
 }
Пример #3
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);
 }
Пример #4
0
 public void Dispose()
 {
     if (this.m_Thread == null)
     {
         return;
     }
     try
     {
         this.m_Finished = true;
         if (this.m_WaveOut != IntPtr.Zero)
         {
             WaveNative.waveOutReset(this.m_WaveOut);
         }
         this.m_Thread.Join();
         this.m_FillProc = (BufferFillEventHandler)null;
         this.FreeBuffers();
         if (this.m_WaveOut != IntPtr.Zero)
         {
             WaveNative.waveOutClose(this.m_WaveOut);
         }
     }
     finally
     {
         this.m_Thread  = (Thread)null;
         this.m_WaveOut = IntPtr.Zero;
     }
 }
Пример #5
0
 public void Dispose()
 {
     if (m_Thread != null)
     {
         try
         {
             m_Finished = true;
             if (m_WaveOut != IntPtr.Zero)
             {
                 WaveNative.waveOutReset(m_WaveOut);
             }
             m_Thread.Join();
             m_FillProc = null;
             FreeBuffers();
             if (m_WaveOut != IntPtr.Zero)
             {
                 WaveNative.waveOutClose(m_WaveOut);
             }
         }
         finally
         {
             m_Thread  = null;
             m_WaveOut = IntPtr.Zero;
         }
     }
     GC.SuppressFinalize(this);
 }
Пример #6
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);
     }
 }
Пример #7
0
 public WaveOutPlayer(int device, WaveFormat format, int bufferSize, int bufferCount, BufferFillEventHandler fillProc)
 {
     m_zero     = format.wBitsPerSample == 8 ? (byte)128 : (byte)0;
     m_FillProc = fillProc;
     WaveOutHelper.Try(WaveNative.waveOutOpen(out m_WaveOut, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     m_Thread = new Thread(new ThreadStart(ThreadProc));
     m_Thread.Start();
 }
Пример #8
0
 public bool Play()
 {
     lock (this)
     {
         this.m_PlayEvent.Reset();
         this.m_Playing = WaveNative.waveOutWrite(this.m_WaveOut, ref this.m_Header, Marshal.SizeOf((object)this.m_Header)) == 0;
         return(this.m_Playing);
     }
 }
Пример #9
0
 public bool Play()
 {
     lock (this)
     {
         m_PlayEvent.Reset();
         m_Playing = WaveNative.waveOutWrite(m_WaveOut, ref m_Header, Marshal.SizeOf(m_Header)) == WaveNative.MMSYSERR_NOERROR;
         return(m_Playing);
     }
 }
Пример #10
0
 public WaveOutBuffer(IntPtr waveOutHandle, int size)
 {
     this.m_WaveOut               = waveOutHandle;
     this.m_HeaderHandle          = GCHandle.Alloc((object)this.m_Header, GCHandleType.Pinned);
     this.m_Header.dwUser         = (IntPtr)GCHandle.Alloc((object)this);
     this.m_HeaderData            = new byte[size];
     this.m_HeaderDataHandle      = GCHandle.Alloc((object)this.m_HeaderData, GCHandleType.Pinned);
     this.m_Header.lpData         = this.m_HeaderDataHandle.AddrOfPinnedObject();
     this.m_Header.dwBufferLength = size;
     WaveOutHelper.Try(WaveNative.waveOutPrepareHeader(this.m_WaveOut, ref this.m_Header, Marshal.SizeOf((object)this.m_Header)));
 }
Пример #11
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)));
        }
Пример #12
0
 public WaveOutPlayer(
     int device,
     WaveFormat format,
     int bufferSize,
     int bufferCount,
     BufferFillEventHandler fillProc)
 {
     this.m_zero     = format.wBitsPerSample == (short)8 ? (byte)128 : (byte)0;
     this.m_FillProc = fillProc;
     WaveOutHelper.Try(WaveNative.waveOutOpen(out this.m_WaveOut, device, format, this.m_BufferProc, 0, 196608));
     this.AllocateBuffers(bufferSize, bufferCount);
     this.m_Thread = new Thread(new ThreadStart(this.ThreadProc));
     this.m_Thread.Start();
 }
Пример #13
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();
 }
Пример #14
0
 public void Dispose()
 {
     if (m_Header.lpData != IntPtr.Zero)
     {
         WaveNative.waveOutUnprepareHeader(m_WaveOut, ref m_Header, Marshal.SizeOf(m_Header));
         m_HeaderHandle.Free();
         m_Header.lpData = IntPtr.Zero;
     }
     m_PlayEvent.Close();
     if (m_HeaderDataHandle.IsAllocated)
     {
         m_HeaderDataHandle.Free();
     }
     GC.SuppressFinalize(this);
 }
Пример #15
0
 internal static void WaveOutProc(IntPtr hdrvr, int uMsg, int dwUser, ref WaveNative.WaveHdr wavhdr, int dwParam2)
 {
     if (uMsg == WaveNative.MM_WOM_DONE)
     {
         try
         {
             GCHandle h = (GCHandle)wavhdr.dwUser;
             WaveOutBuffer buf = (WaveOutBuffer)h.Target;
             buf.OnCompleted();
         }
         catch
         {
         }
     }
 }
Пример #16
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();
        }
Пример #17
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;
        }
Пример #18
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)
     {
     }
 }
Пример #19
0
 public void Record()
 {
     m_RecordEvent.Reset();
     WaveInRecorder.ThrowOnError(WaveNative.waveInAddBuffer(m_WaveIn, ref m_Header, Marshal.SizeOf(m_Header)));
 }