示例#1
0
 unsafe void AllocateHeaders()
 {
     if (this._hwih == IntPtr.Zero)
     {
         throw new InvalidOperationException();
     }
     for (int i = 0; i < _headers.Length; i++)
     {
         if (_headers[i] == IntPtr.Zero)
         {
             WaveHeader *pwh = (WaveHeader *)Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WaveHeader)));
             (*pwh).dwFlags        = 0;
             (*pwh).dwBufferLength = _cc
                                     * _wfx.nBlockAlign;
             (*pwh).lpData = Marshal.AllocHGlobal((*pwh).dwBufferLength);
             (*pwh).dwUser = IntPtr.Zero;
             _headers[i]   = (IntPtr)pwh;
             WinMM.Throw(
                 WinMM.waveInPrepareHeader(this._hwih, _headers[i], Marshal.SizeOf(typeof(WaveHeader))),
                 WinMM.ErrorSource.WaveOut);
             WinMM.Throw(
                 WinMM.waveInAddBuffer(this._hwih, _headers[i], Marshal.SizeOf(typeof(WaveHeader))),
                 WinMM.ErrorSource.WaveOut);
         }
     }
 }
示例#2
0
文件: Mic.cs 项目: azret/mozart
    Mic32 OpenMic()
    {
        var hMic32 = new Microsoft.WinMM.Mic32(1024, 44100, (hMic, hWaveHeader) => {
            WaveHeader *pwh = (WaveHeader *)hWaveHeader;
            if (pwh != null)
            {
                short *psData =
                    (short *)((*pwh).lpData);
                hMic.CaptureData(pwh, psData);
                if (pwh != null)
                {
                    (*pwh).dwFlags = (*pwh).dwFlags & ~WaveHeaderFlags.Done;
                }
                WinMM.Throw(
                    WinMM.waveInAddBuffer(hMic.Handle, hWaveHeader, Marshal.SizeOf(typeof(WaveHeader))),
                    WinMM.ErrorSource.WaveIn);
            }
            PostWinMMMessage(hMic, hWaveHeader);
        });

        try {
            hMic32.Open(false);
        } catch (Exception e) {
            Console.Error?.WriteLine(e);
            hMic32.Dispose();
            return(null);
        }
        return(hMic32);
    }
示例#3
0
        public void Open(bool startmMuted = true)
        {
            const int WaveInMapperDeviceId = -1;

            if (this._hwih != IntPtr.Zero)
            {
                throw new InvalidOperationException("The device is already open.");
            }
            IntPtr h = new IntPtr();

            WinMM.Throw(
                WinMM.waveInOpen(
                    ref h,
                    WaveInMapperDeviceId,
                    ref _wfx,
                    this._hwiproc,
                    (IntPtr)0,
                    WinMM.WaveOpenFlags.CALLBACK_FUNCTION | WinMM.WaveOpenFlags.WAVE_FORMAT_DIRECT),
                WinMM.ErrorSource.WaveIn);
            this._hwih = h;
            this.AllocateHeaders();
            _isMuted = true;
            if (!startmMuted)
            {
                UnMute();
            }
        }