コード例 #1
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);
        }
コード例 #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();
            }
        }
コード例 #3
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);
        }
コード例 #4
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>
 /// <exception cref="ArgumentNullException"><paramref name="directSound"/></exception>
 public DirectSoundPrimaryBuffer(DirectSoundBase directSound)
     : this(directSound, DefaultPrimaryBufferDescription)
 {
 }
コード例 #5
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");
 }
コード例 #6
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]));
 }