コード例 #1
0
        /// <summary>
        /// Retrieves the capabilities of the buffer object.
        /// </summary>
        /// <returns>The capabilities of this sound buffer.</returns>
        public DSBufferCaps GetCaps()
        {
            DSBufferCaps caps;

            DirectSoundException.Try(GetCapsNative(out caps), InterfaceName, "GetCaps");
            return(caps);
        }
コード例 #2
0
        /// <summary>
        /// Gets the frequency, in samples per second, at which the buffer is playing.
        /// </summary>
        /// <returns>The frequency at which the audio buffer is being played, in hertz.</returns>
        public int GetFrequency()
        {
            int f;

            DirectSoundException.Try(GetFrequencyNative(out f), InterfaceName, "GetFrequency");
            return(f);
        }
コード例 #3
0
        /// <summary>
        /// Readies all or part of the buffer for a data write and returns pointers to which data can be written.
        /// </summary>
        /// <param name="offset">Offset, in bytes, from the start of the buffer to the point where the lock begins. This parameter is ignored if <see cref="DSBLock.FromWriteCursor"/> is specified in the <paramref name="lockFlags"/> parameter.</param>
        /// <param name="bytes">Size, in bytes, of the portion of the buffer to lock. The buffer is conceptually circular, so this number can exceed the number of bytes between <paramref name="offset"/> and the end of the buffer.</param>
        /// <param name="audioPtr1">Receives a pointer to the first locked part of the buffer.</param>
        /// <param name="audioBytes1">Receives the number of bytes in the block at <paramref name="audioPtr1"/>. If this value is less than <paramref name="bytes"/>, the lock has wrapped and <paramref name="audioPtr2"/> points to a second block of data at the beginning of the buffer.</param>
        /// <param name="audioPtr2">Receives a pointer to the second locked part of the capture buffer. If <see cref="IntPtr.Zero"/> is returned, the <paramref name="audioPtr1"/> parameter points to the entire locked portion of the capture buffer.</param>
        /// <param name="audioBytes2">Receives the number of bytes in the block at <paramref name="audioPtr2"/>. If <paramref name="audioPtr2"/> is <see cref="IntPtr.Zero"/>, this value is zero.</param>
        /// <param name="lockFlags">Flags modifying the lock event.</param>
        public void Lock(int offset, int bytes, out IntPtr audioPtr1, out int audioBytes1,
                         out IntPtr audioPtr2, out int audioBytes2, DSBLock lockFlags)
        {
            var result = LockNative(offset, bytes, out audioPtr1, out audioBytes1, out audioPtr2, out audioBytes2,
                                    lockFlags);

            DirectSoundException.Try(result, InterfaceName, "Lock");
        }
コード例 #4
0
        private DirectSoundDeviceEnumerator()
        {
            _devices = new List <DirectSoundDevice>();
            var callback = new DSEnumCallback(EnumCallback);

            DirectSoundException.Try(NativeMethods.DirectSoundEnumerate(callback, IntPtr.Zero),
                                     "Interop", "DirectSoundEnumerate");
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <summary>
        /// Retrieves the relative volume of the left and right audio channels.
        /// </summary>
        /// <returns>The relative volume, in hundredths of a decibel.</returns>
        public int GetPan()
        {
            int pani;
            var result = GetPanNative(out pani);

            DirectSoundException.Try(result, InterfaceName, "GetPan");
            return(pani);
        }
コード例 #7
0
 /// <summary>
 /// Sets the frequency at which the audio samples are played.
 /// </summary>
 /// <param name="frequency">Frequency, in hertz (Hz), at which to play the audio samples. A value of <see cref="FrequencyOriginal"/> resets the frequency to the default value of the buffer format.</param>
 /// <remarks>Before setting the frequency, you should ascertain whether the frequency is supported by checking the <see cref="DirectSoundCapabilities.MinSecondarySampleRate"/> and <see cref="DirectSoundCapabilities.MaxSecondarySampleRate"/> members of the <see cref="DirectSoundCapabilities"/> structure for the device. Some operating systems do not support frequencies greater than 100,000 Hz.</remarks>
 public void SetFrequency(int frequency)
 {
     if (frequency < FrequencyMin || frequency > FrequencyMax)
     {
         throw new ArgumentOutOfRangeException("frequency", "Must be between 100 and 20000.");
     }
     DirectSoundException.Try(SetFrequencyNative(frequency), InterfaceName, "SetFrequency");
 }
コード例 #8
0
        /// <summary>
        /// Sets the format of the primary buffer. Whenever this application has the input focus, DirectSound will set the primary buffer to the specified format.
        /// </summary>
        /// <param name="waveFormat">A waveformat that describes the new format for the primary sound buffer.</param>
        public void SetFormat(WaveFormat waveFormat)
        {
            if (waveFormat == null)
            {
                throw new ArgumentNullException("waveFormat");
            }

            DirectSoundException.Try(SetFormatNative(waveFormat), InterfaceName, "SetFormat");
        }
コード例 #9
0
        /// <summary>
        /// Ascertains whether the device driver is certified for DirectX.
        /// </summary>
        /// <returns>A value which indicates whether the device driver is certified for DirectX. On emulated devices, the method returns <see cref="DSCertification.Unsupported"/>.</returns>
        public DSCertification VerifyCertification()
        {
            DSCertification certification;
            var             result = VerifyCertificationNative(out certification);

            if (result == DSResult.Unsupported)
            {
                return(DSCertification.Unsupported);
            }
            DirectSoundException.Try(result, "IDirectSound8",
                                     "VerifyCertification");
            return(certification);
        }
コード例 #10
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);
            }
        }
コード例 #11
0
 /// <summary>
 /// Sets the notification positions. During capture or playback, whenever the read or play cursor reaches one of the specified offsets, the associated event is signaled.
 /// </summary>
 /// <param name="notifies">An array of <see cref="DSBPositionNotify"/> structures.</param>
 public void SetNotificationPositions(DSBPositionNotify[] notifies)
 {
     DirectSoundException.Try(SetNotificationPositionsNative(notifies), "IDirectSoundNotify", "SetNotificationPositions");
 }
コード例 #12
0
 /// <summary>
 /// Restores the memory allocation for a lost sound buffer.
 /// </summary>
 /// <remarks>For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.idirectsoundbuffer8.idirectsoundbuffer8.restore(v=vs.85).aspx"/>.</remarks>
 public void Restore()
 {
     DirectSoundException.Try(RestoreNative(), InterfaceName, "Restore");
 }
コード例 #13
0
 /// <summary>
 /// Sets the attenuation of the sound.
 /// </summary>
 /// <param name="volume">Attenuation, in hundredths of a decibel (dB).</param>
 public void SetVolume(int volume)
 {
     DirectSoundException.Try(SetVolumeNative(volume), InterfaceName, "SetVolume");
 }
コード例 #14
0
 /// <summary>
 /// Causes the sound buffer to stop playing.
 /// </summary>
 /// <remarks>For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.idirectsoundbuffer8.idirectsoundbuffer8.stop(v=vs.85).aspx"/>.</remarks>
 public void Stop()
 {
     DirectSoundException.Try(StopNative(), InterfaceName, "Stop");
 }
コード例 #15
0
 /// <summary>
 /// Initializes a sound buffer object if it has not yet been initialized.
 /// </summary>
 /// <param name="directSound">The device object associated with this buffer.</param>
 /// <param name="bufferDescription">A <see cref="DSBufferDescription"/> structure that contains the values used to initialize this sound buffer.</param>
 public void Initialize(DirectSoundBase directSound, DSBufferDescription bufferDescription)
 {
     DirectSoundException.Try(InitializeNative(directSound, bufferDescription), InterfaceName, "Initialize");
 }
コード例 #16
0
 /// <summary>
 /// Sets the position of the play cursor, which is the point at which the next byte of data is read from the buffer.
 /// </summary>
 /// <param name="playPosition">Offset of the play cursor, in bytes, from the beginning of the buffer.</param>
 public void SetCurrentPosition(int playPosition)
 {
     DirectSoundException.Try(SetCurrentPositionNative(playPosition), InterfaceName, "SetCurrentPosition");
 }
コード例 #17
0
 /// <summary>
 /// Retrieves the position of the play and write cursors in the sound buffer.
 /// </summary>
 /// <param name="playCursorPosition">Receives the offset, in bytes, of the play cursor.</param>
 /// <param name="writeCursorPosition">Receives the offset, in bytes, of the write cursor.</param>
 public void GetCurrentPosition(out int playCursorPosition, out int writeCursorPosition)
 {
     DirectSoundException.Try(GetCurrentPositionNative(out playCursorPosition, out writeCursorPosition),
                              InterfaceName, "GetCurrentPosition");
 }
コード例 #18
0
        /// <summary>
        /// Releases a locked sound buffer.
        /// </summary>
        /// <param name="audioPtr1">Address of the value retrieved in the <c>audioPtr1</c> parameter of the <see cref="Lock"/> method.</param>
        /// <param name="audioBytes1">Number of bytes written to the portion of the buffer at <c>audioPtr1</c>.</param>
        /// <param name="audioPtr2">Address of the value retrieved in the <c>audioPtr2</c> parameter of the <see cref="Lock"/> method.</param>
        /// <param name="audioBytes2">Number of bytes written to the portion of the buffer at <c>audioPtr2</c>.</param>
        public void Unlock(IntPtr audioPtr1, int audioBytes1, IntPtr audioPtr2, int audioBytes2)
        {
            var result = UnlockNative(audioPtr1, audioBytes1, audioPtr2, audioBytes2);

            DirectSoundException.Try(result, InterfaceName, "Unlock");
        }
コード例 #19
0
 /// <summary>
 /// Sets the relative volume of the left and right channels.
 /// </summary>
 /// <param name="pan">Relative volume between the left and right channels. Must be between <see cref="PanLeft"/> and <see cref="PanRight"/>.</param>
 /// <remarks>For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.idirectsoundbuffer8.idirectsoundbuffer8.setpan(v=vs.85).aspx"/>.</remarks>
 public void SetPan(int pan)
 {
     DirectSoundException.Try(SetPanNative(pan), InterfaceName, "SetPan");
 }
コード例 #20
0
 /// <summary>
 /// Causes the sound buffer to play, starting at the play cursor.
 /// </summary>
 /// <param name="flags">Flags specifying how to play the buffer.</param>
 /// <param name="priority">Priority for the sound, used by the voice manager when assigning hardware mixing resources. The lowest priority is 0, and the highest priority is 0xFFFFFFFF. If the buffer was not created with the <see cref="DSBufferCapsFlags.LocDefer"/> flag, this value must be 0.</param>
 public void Play(DSBPlayFlags flags, int priority)
 {
     DirectSoundException.Try(PlayNative(flags, priority), InterfaceName, "Play");
 }