예제 #1
0
 public DirectSoundException(DSResult result, string interfaceName, string member)
     : base(String.Format("{0}.{1} returned 0x{2:x} ({3})", interfaceName, member, result, result), (int)result)
 {
     Result = result;
     InterfaceName = interfaceName;
     Member = member;
 }
예제 #2
0
 /// <summary>
 ///     Throws an <see cref="DirectSoundException" /> if the <paramref name="result" /> is not
 ///     <see cref="DSResult.Ok" />.
 /// </summary>
 /// <param name="result">Errorcode.</param>
 /// <param name="interfaceName">
 ///     Name of the interface which contains the COM-function which returned the specified
 ///     <paramref name="result" />.
 /// </param>
 /// <param name="member">Name of the COM-function which returned the specified <paramref name="result" />.</param>
 public static void Try(DSResult result, string interfaceName, string member)
 {
     if (result != DSResult.Ok)
     {
         throw new DirectSoundException(result, interfaceName, member);
     }
 }
예제 #3
0
 public DirectSoundException(DSResult result, string interfaceName, string member)
     : base(String.Format("{0}.{1} returned 0x{2:x} ({3})", interfaceName, member, result, result), (int)result)
 {
     Result        = result;
     InterfaceName = interfaceName;
     Member        = member;
 }
예제 #4
0
        /// <summary>
        /// Returns the attenuation of the sound.
        /// </summary>
        /// <returns>The attenuation, in hundredths of a decibel.</returns>
        public int GetVolume()
        {
            int      dwvolume;
            DSResult result = GetVolumeNative(out dwvolume);

            DirectSoundException.Try(result, InterfaceName, "GetVolume");
            return(dwvolume);
        }
예제 #5
0
        public DSResult GetVolume(out double volume)
        {
            int      dwvolume;
            DSResult result = GetVolume(out dwvolume);

            if (result != DSResult.DS_OK)
            {
                volume = 0f;
            }
            else
            {
                const double z1 = 0.001; //(1/100)/(dv)
                volume = (MinAttentuation - Math.Pow(2, z1 * dwvolume)) / (MinAttentuation - 1);

                volume = Math.Min(1, Math.Max(0, volume));
            }

            return(result);
        }
예제 #6
0
        /// <summary>
        /// Returns a description of the format of the sound data in the buffer.
        /// </summary>
        /// <returns>A description of the format of the sound data in the buffer. The returned description is either of the type <see cref="WaveFormat"/> or of the type <see cref="WaveFormatExtensible"/>.</returns>
        public WaveFormat GetWaveFormat()
        {
            int      size;
            DSResult result = GetFormatNative(IntPtr.Zero, 0, out size);

            DirectSoundException.Try(result, InterfaceName, "GetWaveFormat");

            IntPtr ptr = Marshal.AllocCoTaskMem(size);

            try
            {
                int n;
                result = GetFormatNative(ptr, size, out n);
                DirectSoundException.Try(result, InterfaceName, "GetWaveFormat");
                return(WaveFormatMarshaler.PointerToWaveFormat(ptr));
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptr);
            }
        }
예제 #7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DirectSoundException" /> class.
 /// </summary>
 /// <param name="result">The Errorcode.</param>
 /// <param name="interfaceName">
 ///     Name of the interface which contains the COM-function which returned the specified
 ///     <paramref name="result" />.
 /// </param>
 /// <param name="member">Name of the COM-function which returned the specified <paramref name="result" />.</param>
 public DirectSoundException(DSResult result, string interfaceName, string member)
     : this((int)result, interfaceName, member)
 {
 }
예제 #8
0
 public static void Try(DSResult result, string interfaceName, string member)
 {
     if (result != DSResult.DS_OK)
         throw new DirectSoundException(result, interfaceName, member);
 }
예제 #9
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DirectSoundException" /> class.
 /// </summary>
 /// <param name="result">The Errorcode.</param>
 /// <param name="interfaceName">
 ///     Name of the interface which contains the COM-function which returned the specified
 ///     <paramref name="result" />.
 /// </param>
 /// <param name="member">Name of the COM-function which returned the specified <paramref name="result" />.</param>
 public DirectSoundException(DSResult result, string interfaceName, string member)
     : this((int) result, interfaceName, member)
 {
 }