Esempio n. 1
0
        /// <summary>
        /// Determines whether or not the device supports a given format.
        /// </summary>
        /// <param name="waveFormat">The format to check.</param>
        /// <returns>true, if the format is supported; false, otherwise.</returns>
        public bool SupportsFormat(WaveFormat waveFormat)
        {
            WAVEFORMATEX wfx = new WAVEFORMATEX();

            wfx.nAvgBytesPerSec = waveFormat.AverageBytesPerSecond;
            wfx.wBitsPerSample  = waveFormat.BitsPerSample;
            wfx.nBlockAlign     = waveFormat.BlockAlign;
            wfx.nChannels       = waveFormat.Channels;
            wfx.wFormatTag      = (short)(int)waveFormat.FormatTag;
            wfx.nSamplesPerSec  = waveFormat.SamplesPerSecond;
            wfx.cbSize          = 0;

            IntPtr     dummy = new IntPtr(0);
            MMSYSERROR ret   = NativeMethods.waveInOpen(
                ref dummy,
                this.deviceId,
                ref wfx,
                null,
                (IntPtr)0,
                WaveOpenFlags.WAVE_FORMAT_QUERY);

            if (ret == MMSYSERROR.MMSYSERR_NOERROR)
            {
                return(true);
            }
            else if (ret == MMSYSERROR.WAVERR_BADFORMAT)
            {
                return(false);
            }
            else
            {
                NativeMethods.Throw(ret, NativeMethods.ErrorSource.WaveIn);
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Releases the resuorces used by this handle.
        /// </summary>
        /// <returns>true, if disposing of the handle succeeded; false, otherwise.</returns>
        protected override bool ReleaseHandle()
        {
            MMSYSERROR ret = NativeMethods.waveOutClose(this);

            return(ret == MMSYSERROR.MMSYSERR_NOERROR);
        }
Esempio n. 3
0
 private static string ErrorMessage(MMSYSERROR result, string function)
 {
     return String.Format("{0} calling {1}", result.ToString(), function);
 }
Esempio n. 4
0
 public static void Try(MMSYSERROR result, string function)
 {
     if (result != MMSYSERROR.MMSYSERR_NOERROR)
         throw new MmException(result, function);
 }
Esempio n. 5
0
 public MmException(MMSYSERROR result, string function)
     : base(MmException.ErrorMessage(result, function))
 {
     this.result = result;
     this.function = function;
 }