示例#1
0
 protected virtual void Dispose(bool disposing)
 {
     lock (_waveOut.LockObj)
     {
         if (_header == null || _waveOut.WaveOutHandle == IntPtr.Zero)
         {
             return;
         }
         try
         {
             MmException.Try(MMInterops.waveOutUnprepareHeader(_waveOut.WaveOutHandle, _header, Marshal.SizeOf(_header)),
                             "waveOutUnprepareHeader"); //don't throw?
         }
         catch (MmException ex)
         {
             if (ex.Result != MmResult.WAVERR_STILLPLAYING)
             {
                 throw; //can't fix bug
             }
         }
         if (_bufferHandle.IsAllocated)
         {
             _bufferHandle.Free();
         }
         if (_headerHandle.IsAllocated)
         {
             _headerHandle.Free();
         }
         if (_userDataHandle.IsAllocated)
         {
             _userDataHandle.Free();
         }
         _header = null;
     }
 }
示例#2
0
        public static float GetVolume(IntPtr waveOut)
        {
            uint     volume = 0;
            MmResult result = MMInterops.waveOutGetVolume(waveOut, out volume);

            if (result != MmResult.MMSYSERR_NOERROR)
            {
                MmException.Try(result, "waveOutGetVolume");
            }
            return(CSCore.Utils.CSMath.IntToWaveOutVolume(volume));
        }
示例#3
0
        public static void SetVolume(IntPtr waveOut, float left, float right)
        {
            uint     tmp    = CSCore.Utils.CSMath.FloatToWaveOutVolume(left, right);
            MmResult result = MMInterops.waveOutSetVolume(waveOut, tmp);

            if (result != MmResult.MMSYSERR_NOERROR)
            {
                MmException.Try(MMInterops.waveOutSetVolume(waveOut, tmp),
                                "waveOutSetVolume");
            }
        }
示例#4
0
        public void Initialize()
        {
            _buffer = new byte[_bufferSize];

            WaveHeader header = new WaveHeader();

            _headerHandle   = GCHandle.Alloc(header);
            _userDataHandle = GCHandle.Alloc(this);
            _bufferHandle   = GCHandle.Alloc(_buffer, GCHandleType.Pinned);

            header.userData     = (IntPtr)_userDataHandle;
            header.loops        = 1;
            header.dataBuffer   = _bufferHandle.AddrOfPinnedObject();
            header.bufferLength = _bufferSize;

            _header = header;
            lock (_waveOut.LockObj)
            {
                MmException.Try(MMInterops.waveOutPrepareHeader(_waveOut.WaveOutHandle, header, Marshal.SizeOf(header)),
                                "waveOutPrepareHeader");
            }
        }
示例#5
0
        public bool WriteData()
        {
            int read;

            lock (_waveOut.WaveSource)
            {
                read = _waveOut.WaveSource.Read(_buffer, 0, _buffer.Length);
            }
            if (read > 0)
            {
                Array.Clear(_buffer, read, _buffer.Length - read);
                lock (_waveOut.LockObj)
                {
                    MmResult result = MMInterops.waveOutWrite(_waveOut.WaveOutHandle, _header, Marshal.SizeOf(_header));
                    if (result != MmResult.MMSYSERR_NOERROR)
                    {
                        MmException.Try(result, "waveOutWrite");
                    }
                    return(result == MmResult.MMSYSERR_NOERROR);
                }
            }
            return(false);
        }
示例#6
0
 public WaveWindow(MMInterops.WaveCallback callback)
 {
     if (callback == null)
         throw new ArgumentNullException("callback equals null");
     _waveCallback = callback;
 }