/// <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();
            }
        }
        private void Create(DirectSoundBase directSound, DSBufferDescription bufferDesc)
        {
            if ((bufferDesc.dwFlags & DSBufferCapsFlags.DSBCAPS_PRIMARYBUFFER) == DSBufferCapsFlags.DSBCAPS_PRIMARYBUFFER)
                throw new ArgumentException("Don t set the PRIMARYBUFFER flag for creating a secondarybuffer.", "bufferDesc");

            _basePtr = directSound.CreateSoundBuffer(bufferDesc, IntPtr.Zero).ToPointer();
        }
        /// <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);
        }
        /// <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);
        }
        public DirectSoundPrimaryBuffer(DirectSoundBase directSound)
        {
            if (directSound == null) throw new ArgumentNullException("directSound");

            DSBufferDescription primaryBufferDesc = new DSBufferDescription()
            {
                dwBufferBytes = 0,
                dwFlags = DSBufferCapsFlags.DSBCAPS_PRIMARYBUFFER | DSBufferCapsFlags.DSBCAPS_CTRLVOLUME | DSBufferCapsFlags.DSBCAPS_CTRL3D,
                dwReserved = 0,
                lpwfxFormat = IntPtr.Zero,
                guid3DAlgorithm = Guid.Empty
            };
            primaryBufferDesc.dwSize = Marshal.SizeOf(primaryBufferDesc);

            _basePtr = directSound.CreateSoundBuffer(primaryBufferDesc, IntPtr.Zero).ToPointer();
        }
        public DirectSoundSecondaryBuffer(DirectSoundBase directSound, WaveFormat waveFormat, int bufferSize)
        {
            if (directSound == null) throw new ArgumentNullException("directSound");

            DSBufferDescription secondaryBufferDesc = new DSBufferDescription()
            {
                dwBufferBytes = (uint)bufferSize * 2,
                dwFlags = DSBufferCapsFlags.DSBCAPS_CTRLFREQUENCY | DSBufferCapsFlags.DSBCAPS_CTRLPAN |
                          DSBufferCapsFlags.DSBCAPS_CTRLVOLUME | DSBufferCapsFlags.DSBCAPS_CTRLPOSITIONNOTIFY |
                          DSBufferCapsFlags.DSBCAPS_GETCURRENTPOSITION2 | DSBufferCapsFlags.DSBCAPS_GLOBALFOCUS |
                          DSBufferCapsFlags.DSBCAPS_STICKYFOCUS,
                dwReserved = 0,
                guid3DAlgorithm = Guid.Empty
            };

            secondaryBufferDesc.dwSize = Marshal.SizeOf(secondaryBufferDesc);
            GCHandle hWaveFormat = GCHandle.Alloc(waveFormat, GCHandleType.Pinned);
            secondaryBufferDesc.lpwfxFormat = hWaveFormat.AddrOfPinnedObject();

            Create(directSound, secondaryBufferDesc);

            hWaveFormat.Free();
        }
Esempio n. 7
0
 public DSResult Initialize(DirectSoundBase directSound, DSBufferDescription bufferDesc)
 {
     return InteropCalls.CalliMethodPtr(_basePtr, directSound.BasePtr.ToPointer(), &bufferDesc, ((void**)(*(void**)_basePtr))[10]);
 }
Esempio n. 8
0
 public void CanCreateDirectSound()
 {
     DirectSoundBase.Create((Guid)DirectSoundDevice.DefaultDevice).Dispose();
 }
 /// <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>
 /// <exception cref="ArgumentNullException"><paramref name="directSound"/></exception>
 public DirectSoundPrimaryBuffer(DirectSoundBase directSound)
     : this(directSound, DefaultPrimaryBufferDescription)
 {
 }
Esempio 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>
 public void Initialize(DirectSoundBase directSound, DSBufferDescription bufferDescription)
 {
     DirectSoundException.Try(InitializeNative(directSound, bufferDescription), InterfaceName, "Initialize");
 }
 public DirectSoundSecondaryBuffer(DirectSoundBase directSound, DSBufferDescription bufferDesc)
 {
     Create(directSound, bufferDesc);
 }