Exemplo n.º 1
0
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public void Dispose()
        {
            if (m_IsDisposed)
            {
                return;
            }
            m_IsDisposed = true;

            // Release events.
            this.BufferFull = null;

            try{
                // If recording, we need to reset wav device first.
                WavMethods.waveInReset(m_pWavDevHandle);

                // If there are unprepared wav headers, we need to unprepare these.
                foreach (BufferItem item in m_pBuffers)
                {
                    WavMethods.waveInUnprepareHeader(m_pWavDevHandle, item.HeaderHandle.AddrOfPinnedObject(), Marshal.SizeOf(item.Header));
                    item.Dispose();
                }

                // Close input device.
                WavMethods.waveInClose(m_pWavDevHandle);

                m_pInDevice     = null;
                m_pWavDevHandle = IntPtr.Zero;
            }
            catch {
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes first first filled buffer in queue and disposes it if done.
        /// </summary>
        /// <param name="state">User data.</param>
        private void ProcessFirstBuffer(object state)
        {
            try {
                lock (m_pBuffers) {
                    if (m_IsDisposed)
                    {
                        return;
                    }
                    BufferItem item = m_pBuffers[0];

                    // Raise BufferFull event.
                    OnBufferFull(item.Data);
                    if (m_IsDisposed)
                    {
                        return;
                    }
                    // Clean up.
                    WavMethods.waveInUnprepareHeader(m_pWavDevHandle, item.HeaderHandle.AddrOfPinnedObject(), Marshal.SizeOf(item.Header));
                    m_pBuffers.Remove(item);
                    item.Dispose();
                }

                EnsureBuffers();
            } catch {
            }
        }
Exemplo n.º 3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!m_IsDisposed)
            {
                // Release events.
                this.BufferFull = null;

                try
                {
                    // If recording, we need to reset wav device first.
                    WavMethods.waveInReset(m_pWavDevHandle);

                    // If there are unprepared wav headers, we need to unprepare these.
                    lock (m_pBuffers)
                    {
                        foreach (BufferItem item in m_pBuffers)
                        {
                            try
                            {
                                WavMethods.waveInUnprepareHeader(m_pWavDevHandle, item.HeaderHandle.AddrOfPinnedObject(), Marshal.SizeOf(item.Header));
                            }
                            catch
                            {
                                Debug.WriteLine("WaveIn.Dispose() - WavMethods.waveInUnprepareHeader()");
                            }
                            item.Dispose();
                        }
                    }

                    // Close input device.
                    Debug.WriteLine("WaveIn.Dispose() - waveInClose");
                    try
                    {
                        WavMethods.waveInClose(m_pWavDevHandle);
                    }
                    catch
                    {
                        Debug.WriteLine("WaveIn.Dispose() - WavMethods.waveInClose()");
                    }
                    finally
                    {
                        m_pInDevice     = null;
                        m_pWavDevHandle = IntPtr.Zero;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("WaveIn.Dispose() - " + ex.Message);
                }
            }
            m_IsDisposed = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Processes first first filled buffer in queue and disposes it if done.
        /// </summary>
        /// <param name="state">User data.</param>
        private void ProcessFirstBuffer(object state)
        {
            if (m_IsRecording)
            {
                BufferItem item;
                try
                {
                    lock (m_pBuffers)
                    {
                        item = m_pBuffers[0];

                        // Raise BufferFull event.
                        OnBufferFull(item.Data);

                        // Clean up.
                        try
                        {
                            Debug.WriteLine("WaveIn.ProcessFirstBuffer() - waveInUnprepareHeader");
                            WavMethods.waveInUnprepareHeader(m_pWavDevHandle, item.HeaderHandle.AddrOfPinnedObject(), Marshal.SizeOf(item.Header));
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("WaveIn.ProcessFirstBuffer() - WavMethods.waveInUnprepareHeader - " + ex.Message);
                        }
                        finally
                        {
                            m_pBuffers.RemoveAt(0);
                            Debug.WriteLine("WaveIn.ProcessFirstBuffer() - cleanup buffers");
                            item.Dispose();
                        }
                    }

                    Debug.WriteLine("WaveIn.ProcessFirstBuffer() - EnsureBuffers()");
                    EnsureBuffers();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("WaveIn.ProcessFirstBuffer() - " + ex.Message);
                }
            }
        }