Ejemplo n.º 1
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>
 /// <param name="soundBuffer">A variable that receives the IDirectSoundBuffer interface of the new buffer object.</param>
 /// <returns>DSResult</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 DSResult CreateSoundBufferNative(DSBufferDescription bufferDesc, out IntPtr soundBuffer, IntPtr pUnkOuter)
 {
     fixed(void *ptrsoundbuffer = &soundBuffer)
     {
         return(InteropCalls.CalliMethodPtr(UnsafeBasePtr, &bufferDesc, ptrsoundbuffer, (void *)pUnkOuter, ((void **)(*(void **)UnsafeBasePtr))[3]));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectSoundSecondaryBuffer"/> class.
        /// </summary>
        /// <param name="directSound">A <see cref="DirectSoundBase"/> instance which provides the <see cref="DirectSoundBase.CreateSoundBuffer"/> method.</param>
        /// <param name="waveFormat">The <see cref="WaveFormat"/> of the sound buffer.</param>
        /// <param name="bufferSize">The buffer size. Internally, the <see cref="DSBufferDescription.BufferBytes"/> will be set to <paramref name="bufferSize"/> * 2.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="directSound"/> or <paramref name="waveFormat"/></exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> must be a value between 4 and 0x0FFFFFFF.</exception>
        public DirectSoundSecondaryBuffer(DirectSoundBase directSound, WaveFormat waveFormat, int bufferSize)
        {
            if (directSound == null)
                throw new ArgumentNullException("directSound");
            if (waveFormat == null)
                throw new ArgumentNullException("waveFormat");
            if(bufferSize < 4 || bufferSize > 0x0FFFFFFF)
                throw new ArgumentOutOfRangeException("bufferSize");

            DSBufferDescription secondaryBufferDesc = new DSBufferDescription()
            {
                BufferBytes = bufferSize,
                Flags = DSBufferCapsFlags.ControlFrequency | DSBufferCapsFlags.ControlPan |
                          DSBufferCapsFlags.ControlVolume | DSBufferCapsFlags.ControlPositionNotify |
                          DSBufferCapsFlags.GetCurrentPosition2 | DSBufferCapsFlags.GlobalFocus |
                          DSBufferCapsFlags.StickyFocus,
                Reserved = 0,
                Guid3DAlgorithm = Guid.Empty
            };

            secondaryBufferDesc.Size = Marshal.SizeOf(secondaryBufferDesc);
            GCHandle hWaveFormat = GCHandle.Alloc(waveFormat, GCHandleType.Pinned);
            try
            {
                secondaryBufferDesc.PtrFormat = hWaveFormat.AddrOfPinnedObject();
                //Create(directSound, secondaryBufferDesc);
                BasePtr = directSound.CreateSoundBuffer(secondaryBufferDesc, IntPtr.Zero);
            }
            finally
            {
                hWaveFormat.Free();
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectSoundSecondaryBuffer"/> class.
        /// </summary>
        /// <param name="directSound">A <see cref="DirectSoundBase"/> instance which provides the <see cref="DirectSoundBase.CreateSoundBuffer"/> method.</param>
        /// <param name="bufferDescription">The buffer description which describes the buffer to create.</param>        
        /// <exception cref="System.ArgumentNullException"><paramref name="directSound"/></exception>
        /// <exception cref="System.ArgumentException">
        /// The <paramref name="bufferDescription"/> is invalid.
        /// </exception>
        public DirectSoundSecondaryBuffer(DirectSoundBase directSound, DSBufferDescription bufferDescription)
        {
            if (directSound == null)
                throw new ArgumentNullException("directSound");
            if((bufferDescription.Flags & DSBufferCapsFlags.PrimaryBuffer) == DSBufferCapsFlags.PrimaryBuffer)
                throw new ArgumentException("The PrimaryBuffer is set.", "bufferDescription");
            if (bufferDescription.BufferBytes < 4 || bufferDescription.BufferBytes > 0x0FFFFFFF)
                throw new ArgumentException("Invalid BufferBytes value.", "bufferDescription");

            BasePtr = directSound.CreateSoundBuffer(bufferDescription, IntPtr.Zero);

            //Create(directSound, bufferDesc);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectSoundPrimaryBuffer"/> class.
        /// </summary>
        /// <param name="directSound">A <see cref="DirectSoundBase"/> instance which provides the <see cref="DirectSoundBase.CreateSoundBuffer"/> method.</param>
        /// <param name="bufferDescription">The buffer description which describes the buffer to create.</param>
        /// <exception cref="ArgumentNullException"><paramref name="directSound"/></exception>
        /// <exception cref="ArgumentException">The <paramref name="bufferDescription"/> is invalid.</exception>
        public DirectSoundPrimaryBuffer(DirectSoundBase directSound, DSBufferDescription bufferDescription)
        {
            if (directSound == null)
                throw new ArgumentNullException("directSound");

            if((bufferDescription.Flags & DSBufferCapsFlags.PrimaryBuffer) != DSBufferCapsFlags.PrimaryBuffer)
                throw new ArgumentException("The PrimaryBuffer flag is not set.", "bufferDescription");
            if(bufferDescription.BufferBytes != 0)
                throw new ArgumentException("BufferBytes must be zero.", "bufferDescription");
            bufferDescription.Size = Marshal.SizeOf(bufferDescription);
            if (bufferDescription.PtrFormat != IntPtr.Zero)
                throw new ArgumentException("PtrFormat must be NULL.", "bufferDescription");

            BasePtr = directSound.CreateSoundBuffer(bufferDescription, IntPtr.Zero);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectSoundSecondaryBuffer"/> class.
        /// </summary>
        /// <param name="directSound">A <see cref="DirectSoundBase"/> instance which provides the <see cref="DirectSoundBase.CreateSoundBuffer"/> method.</param>
        /// <param name="bufferDescription">The buffer description which describes the buffer to create.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="directSound"/></exception>
        /// <exception cref="System.ArgumentException">
        /// The <paramref name="bufferDescription"/> is invalid.
        /// </exception>
        public DirectSoundSecondaryBuffer(DirectSoundBase directSound, DSBufferDescription bufferDescription)
        {
            if (directSound == null)
            {
                throw new ArgumentNullException("directSound");
            }
            if ((bufferDescription.Flags & DSBufferCapsFlags.PrimaryBuffer) == DSBufferCapsFlags.PrimaryBuffer)
            {
                throw new ArgumentException("The PrimaryBuffer is set.", "bufferDescription");
            }
            if (bufferDescription.BufferBytes < 4 || bufferDescription.BufferBytes > 0x0FFFFFFF)
            {
                throw new ArgumentException("Invalid BufferBytes value.", "bufferDescription");
            }

            BasePtr = directSound.CreateSoundBuffer(bufferDescription, IntPtr.Zero);

            //Create(directSound, bufferDesc);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectSoundSecondaryBuffer"/> class.
        /// </summary>
        /// <param name="directSound">A <see cref="DirectSoundBase"/> instance which provides the <see cref="DirectSoundBase.CreateSoundBuffer"/> method.</param>
        /// <param name="waveFormat">The <see cref="WaveFormat"/> of the sound buffer.</param>
        /// <param name="bufferSize">The buffer size. Internally, the <see cref="DSBufferDescription.BufferBytes"/> will be set to <paramref name="bufferSize"/> * 2.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="directSound"/> or <paramref name="waveFormat"/></exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> must be a value between 4 and 0x0FFFFFFF.</exception>
        public DirectSoundSecondaryBuffer(DirectSoundBase directSound, WaveFormat waveFormat, int bufferSize)
        {
            if (directSound == null)
            {
                throw new ArgumentNullException("directSound");
            }
            if (waveFormat == null)
            {
                throw new ArgumentNullException("waveFormat");
            }
            if (bufferSize < 4 || bufferSize > 0x0FFFFFFF)
            {
                throw new ArgumentOutOfRangeException("bufferSize");
            }

            DSBufferDescription secondaryBufferDesc = new DSBufferDescription()
            {
                BufferBytes = bufferSize,
                Flags       = DSBufferCapsFlags.ControlFrequency | DSBufferCapsFlags.ControlPan |
                              DSBufferCapsFlags.ControlVolume | DSBufferCapsFlags.ControlPositionNotify |
                              DSBufferCapsFlags.GetCurrentPosition2 | DSBufferCapsFlags.GlobalFocus |
                              DSBufferCapsFlags.StickyFocus,
                Reserved        = 0,
                Guid3DAlgorithm = Guid.Empty
            };

            secondaryBufferDesc.Size = Marshal.SizeOf(secondaryBufferDesc);
            GCHandle hWaveFormat = GCHandle.Alloc(waveFormat, GCHandleType.Pinned);

            try
            {
                secondaryBufferDesc.PtrFormat = hWaveFormat.AddrOfPinnedObject();
                //Create(directSound, secondaryBufferDesc);
                BasePtr = directSound.CreateSoundBuffer(secondaryBufferDesc, IntPtr.Zero);
            }
            finally
            {
                hWaveFormat.Free();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectSoundPrimaryBuffer"/> class.
        /// </summary>
        /// <param name="directSound">A <see cref="DirectSoundBase"/> instance which provides the <see cref="DirectSoundBase.CreateSoundBuffer"/> method.</param>
        /// <param name="bufferDescription">The buffer description which describes the buffer to create.</param>
        /// <exception cref="ArgumentNullException"><paramref name="directSound"/></exception>
        /// <exception cref="ArgumentException">The <paramref name="bufferDescription"/> is invalid.</exception>
        public DirectSoundPrimaryBuffer(DirectSoundBase directSound, DSBufferDescription bufferDescription)
        {
            if (directSound == null)
            {
                throw new ArgumentNullException("directSound");
            }

            if ((bufferDescription.Flags & DSBufferCapsFlags.PrimaryBuffer) != DSBufferCapsFlags.PrimaryBuffer)
            {
                throw new ArgumentException("The PrimaryBuffer flag is not set.", "bufferDescription");
            }
            if (bufferDescription.BufferBytes != 0)
            {
                throw new ArgumentException("BufferBytes must be zero.", "bufferDescription");
            }
            bufferDescription.Size = Marshal.SizeOf(bufferDescription);
            if (bufferDescription.PtrFormat != IntPtr.Zero)
            {
                throw new ArgumentException("PtrFormat must be NULL.", "bufferDescription");
            }

            BasePtr = directSound.CreateSoundBuffer(bufferDescription, IntPtr.Zero);
        }
Ejemplo n.º 9
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");
 }
Ejemplo n.º 10
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>
 /// <returns>DSResult</returns>
 public DSResult InitializeNative(DirectSoundBase directSound, DSBufferDescription bufferDescription)
 {
     return InteropCalls.CalliMethodPtr(UnsafeBasePtr, directSound.BasePtr.ToPointer(), &bufferDescription, ((void**)(*(void**)UnsafeBasePtr))[10]);
 }
Ejemplo n.º 11
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");
 }
Ejemplo n.º 12
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>
 /// <returns>DSResult</returns>
 public DSResult InitializeNative(DirectSoundBase directSound, DSBufferDescription bufferDescription)
 {
     return(InteropCalls.CalliMethodPtr(UnsafeBasePtr, directSound.BasePtr.ToPointer(), &bufferDescription, ((void **)(*(void **)UnsafeBasePtr))[10]));
 }