public BufferDescription(BufferCapabilities capabilities, int size, IntPtr format) { dwSize = Marshal.SizeOf(typeof(BufferDescription)); dwFlags = capabilities; dwBufferBytes = size; lpwfxFormat = format; }
public Sound(IntPtr handle) { test[1] = test[0] + 2; test[2] = test[1] + 2; test[3] = test[2] + 1; test[4] = test[3] + 2; test[5] = test[4] + 2; test[6] = test[5] + 2; DirectSound directSound = new DirectSound(); // Set Cooperative Level to PRIORITY (priority level can call the SetFormat and Compact methods) // directSound.SetCooperativeLevel(handle, CooperativeLevel.Priority); // Create PrimarySoundBuffer var primaryBufferDesc = new SoundBufferDescription(); primaryBufferDesc.Flags = BufferFlags.PrimaryBuffer; primaryBufferDesc.AlgorithmFor3D = Guid.Empty; var primarySoundBuffer = new PrimarySoundBuffer(directSound, primaryBufferDesc); // Play the PrimarySound Buffer primarySoundBuffer.Play(0, PlayFlags.Looping); // Default WaveFormat Stereo 44100 16 bit waveFormat = new WaveFormat(); // Create SecondarySoundBuffer var secondaryBufferDesc = new SoundBufferDescription(); secondaryBufferDesc.BufferBytes = waveFormat.ConvertLatencyToByteSize(10000); secondaryBufferDesc.Format = waveFormat; secondaryBufferDesc.Flags = BufferFlags.GetCurrentPosition2 | BufferFlags.ControlPositionNotify | BufferFlags.GlobalFocus | BufferFlags.ControlVolume | BufferFlags.StickyFocus; secondaryBufferDesc.AlgorithmFor3D = Guid.Empty; secondarySoundBuffer = new SecondarySoundBuffer(directSound, secondaryBufferDesc); // Get Capabilties from secondary sound buffer capabilities = secondarySoundBuffer.Capabilities; sounds = new short[capabilities.BufferBytes / waveFormat.BlockAlign]; // Play the song secondarySoundBuffer.Play(0, PlayFlags.Looping); for (int i = 0; i < sounds.Length; i++) { sounds[i] = 0; } }
/// <summary> /// Creates a new strategy for multi-buffering on this component with the /// required buffer capabilities. This is useful, for example, if only /// accelerated memory or page flipping is desired (as specified by the /// buffer capabilities). /// <para> /// Each time this method /// is called, the existing buffer strategy for this component is discarded. /// </para> /// </summary> /// <param name="numBuffers"> number of buffers to create </param> /// <param name="caps"> the required capabilities for creating the buffer strategy; /// cannot be <code>null</code> </param> /// <exception cref="AWTException"> if the capabilities supplied could not be /// supported or met; this may happen, for example, if there is not enough /// accelerated memory currently available, or if page flipping is specified /// but not possible. </exception> /// <exception cref="IllegalArgumentException"> if numBuffers is less than 1, or if /// caps is <code>null</code> </exception> /// <seealso cref= #getBufferStrategy /// @since 1.4 </seealso> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void createBufferStrategy(int numBuffers, BufferCapabilities caps) throws AWTException public override void CreateBufferStrategy(int numBuffers, BufferCapabilities caps) { base.CreateBufferStrategy(numBuffers, caps); }