示例#1
0
        protected int CloseFile()
        {
            lock (m_Lock)
            {
                if (m_Stream != null)
                {
                    WaveFormatEx _wfx = Pins[0].CurrentMediaType;

                    int    _size;
                    byte[] _buffer;
                    IntPtr _ptr;

                    OUTPUT_FILE_HEADER _header = new OUTPUT_FILE_HEADER();

                    _header.dwRiff         = RIFF_TAG;
                    _header.dwFileSize     = (uint)m_Stream.Length - 2 * 4;
                    _header.dwWave         = WAVE_TAG;
                    _header.dwFormat       = FMT__TAG;
                    _header.dwFormatLength = (uint)Marshal.SizeOf(_wfx);

                    _size   = Marshal.SizeOf(_header);
                    _buffer = new byte[_size];
                    _ptr    = Marshal.AllocCoTaskMem(_size);
                    Marshal.StructureToPtr(_header, _ptr, true);
                    Marshal.Copy(_ptr, _buffer, 0, _size);
                    m_Stream.Write(_buffer, 0, _size);
                    Marshal.FreeCoTaskMem(_ptr);

                    _size   = Marshal.SizeOf(_wfx);
                    _buffer = new byte[_size];
                    _ptr    = Marshal.AllocCoTaskMem(_size);
                    Marshal.StructureToPtr(_wfx, _ptr, true);
                    Marshal.Copy(_ptr, _buffer, 0, _size);
                    m_Stream.Write(_buffer, 0, _size);
                    Marshal.FreeCoTaskMem(_ptr);

                    OUTPUT_DATA_HEADER _data = new OUTPUT_DATA_HEADER();
                    _data.dwData       = DATA_TAG;
                    _data.dwDataLength = (uint)(m_Stream.Length - Marshal.SizeOf(_header) - _header.dwFormatLength - Marshal.SizeOf(_data));

                    _size   = Marshal.SizeOf(_data);
                    _buffer = new byte[_size];
                    _ptr    = Marshal.AllocCoTaskMem(_size);
                    Marshal.StructureToPtr(_data, _ptr, true);
                    Marshal.Copy(_ptr, _buffer, 0, _size);
                    m_Stream.Write(_buffer, 0, _size);
                    Marshal.FreeCoTaskMem(_ptr);

                    m_Stream.Dispose();
                    m_Stream = null;
                }
            }
            return(NOERROR);
        }
示例#2
0
        protected int OpenFile()
        {
            if (m_Stream == null && m_sFileName != "" && Pins[0].IsConnected)
            {
                m_Stream = new FileStream(m_sFileName, FileMode.Create, FileAccess.Write, FileShare.Read);

                WaveFormatEx _wfx = Pins[0].CurrentMediaType;

                int    _size;
                byte[] _buffer;
                IntPtr _ptr;

                OUTPUT_FILE_HEADER _header = new OUTPUT_FILE_HEADER();

                _header.dwRiff         = RIFF_TAG;
                _header.dwFileSize     = 0;
                _header.dwWave         = WAVE_TAG;
                _header.dwFormat       = FMT__TAG;
                _header.dwFormatLength = (uint)Marshal.SizeOf(_wfx);

                _size   = Marshal.SizeOf(_header);
                _buffer = new byte[_size];
                _ptr    = Marshal.AllocCoTaskMem(_size);
                Marshal.StructureToPtr(_header, _ptr, true);
                Marshal.Copy(_ptr, _buffer, 0, _size);
                m_Stream.Write(_buffer, 0, _size);
                Marshal.FreeCoTaskMem(_ptr);

                _size   = Marshal.SizeOf(_wfx);
                _buffer = new byte[_size];
                _ptr    = Marshal.AllocCoTaskMem(_size);
                Marshal.StructureToPtr(_wfx, _ptr, true);
                Marshal.Copy(_ptr, _buffer, 0, _size);
                m_Stream.Write(_buffer, 0, _size);
                Marshal.FreeCoTaskMem(_ptr);

                OUTPUT_DATA_HEADER _data = new OUTPUT_DATA_HEADER();
                _data.dwData       = DATA_TAG;
                _data.dwDataLength = 0;

                _size   = Marshal.SizeOf(_data);
                _buffer = new byte[_size];
                _ptr    = Marshal.AllocCoTaskMem(_size);
                Marshal.StructureToPtr(_data, _ptr, true);
                Marshal.Copy(_ptr, _buffer, 0, _size);
                m_Stream.Write(_buffer, 0, _size);
                Marshal.FreeCoTaskMem(_ptr);

                return(NOERROR);
            }
            return(S_FALSE);
        }