示例#1
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);
        }
示例#2
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);
        }
示例#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
        /// <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);
        }
示例#5
0
        /// <summary>
        /// Creates a new secondary buffer that shares the original buffer's memory.
        /// </summary>
        /// <typeparam name="T">Type of the buffer to duplicate.</typeparam>
        /// <param name="bufferOriginal">The buffer to duplicate.</param>
        /// <returns>The duplicated buffer.</returns>
        /// <remarks>For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.idirectsound8.idirectsound8.duplicatesoundbuffer(v=vs.85).aspx"/>.</remarks>
        public T DuplicateSoundBuffer <T>(T bufferOriginal) where T : DirectSoundBuffer
        {
            IntPtr resultPtr;

            DirectSoundException.Try(DuplicateSoundBufferNative(bufferOriginal.BasePtr, out resultPtr), "IDirectSound8",
                                     "DuplicateSoundBuffer");
            return((T)Activator.CreateInstance(typeof(T), resultPtr));
        }
示例#6
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");
 }
示例#7
0
        private DirectSoundDeviceEnumerator()
        {
            _devices = new List <DirectSoundDevice>();
            var callback = new DSEnumCallback(EnumCallback);

            DirectSoundException.Try(NativeMethods.DirectSoundEnumerate(callback, IntPtr.Zero),
                                     "Interop", "DirectSoundEnumerate");
        }
示例#8
0
        /// <summary>
        /// Creates a sound buffer object to manage audio samples.
        /// </summary>
        /// <param name="bufferDesc">A <see cref="DSBufferDescription"/> structure that describes the sound buffer to create.</param>
        /// <param name="pUnkOuter">Must be <see cref="IntPtr.Zero"/>.</param>
        /// <returns>A variable that receives the IDirectSoundBuffer interface of the new buffer object.</returns>
        /// <remarks>For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.idirectsound8.idirectsound8.createsoundbuffer%28v=vs.85%29.aspx"/>.</remarks>
        public IntPtr CreateSoundBuffer(DSBufferDescription bufferDesc, IntPtr pUnkOuter)
        {
            IntPtr soundBuffer;

            DirectSoundException.Try(CreateSoundBufferNative(bufferDesc, out soundBuffer, pUnkOuter),
                                     "IDirectSound8", "CreateSoundBuffer");
            return(soundBuffer);
        }
示例#9
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);
        }
示例#10
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");
        }
示例#11
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);
        }
示例#12
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);
            }
        }
示例#13
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");
 }
示例#14
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");
 }
示例#15
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");
 }
示例#16
0
 /// <summary>
 /// Initializes a device object that was created by using the CoCreateInstance function.
 /// </summary>
 /// <param name="device">The globally unique identifier (GUID) specifying the sound driver to which this device object binds. Pass null to select the primary sound driver.</param>
 public void Initialize(Guid?device)
 {
     DirectSoundException.Try(InitializeNative(device), "IDirectSound8", "Initialize");
 }
示例#17
0
 /// <summary>
 /// Has no effect. See remarks.
 /// </summary>
 /// <remarks>This method was formerly used for compacting the on-board memory of ISA sound cards.</remarks>
 public void Compact()
 {
     DirectSoundException.Try(CompactNative(), "IDirectSound8", "Compact");
 }
示例#18
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");
 }
示例#19
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");
        }
示例#20
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");
 }
示例#21
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");
 }
示例#22
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");
 }
示例#23
0
 /// <summary>
 /// Specifies the speaker configuration of the device.
 /// </summary>
 /// <param name="speakerConfig">The speaker configuration.</param>
 /// <remarks>
 /// In Windows Vista and later versions of Windows, <see cref="GetSpeakerConfig"/> is a NOP. For Windows Vista and later versions, the speaker configuration is a system setting that should not be modified by an application. End users can set the speaker configuration through control panels.
 /// For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.idirectsound8.idirectsound8.setspeakerconfig(v=vs.85).aspx"/>.
 /// </remarks>
 public void SetSpeakerConfig(DSSpeakerConfigurations speakerConfig)
 {
     DirectSoundException.Try(SetSpeakerConfigNative(speakerConfig), "IDirectSound8", "SetSpeakerConfig");
 }
示例#24
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");
 }
示例#25
0
 /// <summary>
 /// Sets the cooperative level of the application for this sound device.
 /// </summary>
 /// <param name="hWnd">Handle to the application window.</param>
 /// <param name="level">The requested level.</param>
 public void SetCooperativeLevel(IntPtr hWnd, DSCooperativeLevelType level)
 {
     DirectSoundException.Try(SetCooperativeLevelNative(hWnd, level), "IDirectSound8", "SetCooperativeLevel");
 }
示例#26
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");
 }