public void CanSetExclusiveCooperativeLevel() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_EXCLUSIVE); } }
public void CanSetWritePrimaryCooperativeLevel() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_WRITEPRIMARY); } }
public void CanSetPriorityCooperativeLevel() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_PRIORITY); } }
public void CanSetNormalCooperativeLevel() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_NORMAL); } }
public void CanPlayBuffers() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_NORMAL); WaveFormat waveFormat = new WaveFormat(44100, 16, 2); using (var primaryBuffer = new DirectSoundPrimaryBuffer(dsound)) using (var secondaryBuffer = new DirectSoundSecondaryBuffer(dsound, waveFormat, (int)waveFormat.MillisecondsToBytes(10000))) { primaryBuffer.Play(DSBPlayFlags.DSBPLAY_LOOPING); var caps = secondaryBuffer.BufferCaps; var data = GenerateData(caps.dwBufferBytes / 2, waveFormat); if (secondaryBuffer.Write(data, 0, data.Length)) { secondaryBuffer.Play(DSBPlayFlags.DSBPLAY_LOOPING); } else { Assert.Fail("Could not write data."); } Thread.Sleep(1); } } }
public void CanGetCaps() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_NORMAL); var caps = dsound.Caps; } }
public void CanCreatePrimaryBuffer() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_NORMAL); new DirectSoundPrimaryBuffer(dsound).Dispose(); } }
public void CanCheckForSupportedFormat() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_NORMAL); dsound.SupportsFormat(new WaveFormat()); } }
public void CanCreateSecondaryBuffer() { using (var dsound = CreateDirectSound8()) { dsound.SetCooperativeLevel(DSUtils.GetDesktopWindow(), DSCooperativeLevelType.DSSCL_NORMAL); new DirectSoundPrimaryBuffer(dsound).Dispose(); WaveFormat waveFormat = new WaveFormat(); new DirectSoundSecondaryBuffer(dsound, waveFormat, (int)waveFormat.MillisecondsToBytes(100)).Dispose(); } }
private void InitializeInternal() { //Use Desktophandle as default handle IntPtr handle = DSUtils.GetDesktopWindow(); IntPtr pdsound; DirectSoundException.Try(NativeMethods.DirectSoundCreate8(ref _device, out pdsound, IntPtr.Zero), "DSInterop", "DirectSoundCreate8"); _directSound = new DirectSound8(pdsound); _directSound.SetCooperativeLevel(handle, DSCooperativeLevelType.Normal); //use normal as default if (!_directSound.SupportsFormat(_source.WaveFormat)) { if (_source.WaveFormat.WaveFormatTag == AudioEncoding.IeeeFloat) //directsound does not support ieeefloat { _source = _source.ToSampleSource().ToWaveSource(16); } WaveFormat format16Bit = (WaveFormat)_source.WaveFormat.Clone(); format16Bit.BitsPerSample = 16; WaveFormat format8Bit = (WaveFormat)_source.WaveFormat.Clone(); format8Bit.BitsPerSample = 8; if (_directSound.SupportsFormat(format16Bit)) { _source = _source.ToSampleSource().ToWaveSource(16); } else if (_directSound.SupportsFormat(format8Bit)) { _source = _source.ToSampleSource().ToWaveSource(8); } else { throw new NotSupportedException( "WaveFormat of the source is not supported."); } if (!_directSound.SupportsFormat(_source.WaveFormat)) { throw new NotSupportedException( "WaveFormat of the source is not supported."); } } WaveFormat waveFormat = _source.WaveFormat; var bufferSize = (int)waveFormat.MillisecondsToBytes(_latency); _primaryBuffer = new DirectSoundPrimaryBuffer(_directSound); _secondaryBuffer = new DirectSoundSecondaryBuffer(_directSound, waveFormat, bufferSize * 2); }
private void InitializeInternal() { //Use Desktophandle as default handle IntPtr handle = DSUtils.GetDesktopWindow(); IntPtr pdsound; DirectSoundException.Try(NativeMethods.DirectSoundCreate8(ref _device, out pdsound, IntPtr.Zero), "DSInterop", "DirectSoundCreate8"); _directSound = new DirectSound8(pdsound); _directSound.SetCooperativeLevel(handle, DSCooperativeLevelType.DSSCL_NORMAL); //use normal as default if (!_directSound.SupportsFormat(_source.WaveFormat)) { if (_source.WaveFormat.WaveFormatTag == AudioEncoding.IeeeFloat) { _source = _source.ToSampleSource().ToWaveSource(16); } if (_directSound.SupportsFormat(new WaveFormat(_source.WaveFormat.SampleRate, 16, _source.WaveFormat.Channels, _source.WaveFormat.WaveFormatTag))) { _source = _source.ToSampleSource().ToWaveSource(16); } else if (_directSound.SupportsFormat(new WaveFormat(_source.WaveFormat.SampleRate, 8, _source.WaveFormat.Channels, _source.WaveFormat.WaveFormatTag))) { _source = _source.ToSampleSource().ToWaveSource(8); } else { throw new InvalidOperationException("Invalid WaveFormat. WaveFormat specified by parameter {_source} is not supported by this DirectSound-Device."); } if (!_directSound.SupportsFormat(_source.WaveFormat)) { throw new InvalidOperationException("Invalid WaveFormat. WaveFormat specified by parameter {_source} is not supported by this DirectSound-Device."); } } WaveFormat waveFormat = _source.WaveFormat; int bufferSize = (int)waveFormat.MillisecondsToBytes(_latency); _primaryBuffer = new DirectSoundPrimaryBuffer(_directSound); _secondaryBuffer = new DirectSoundSecondaryBuffer(_directSound, waveFormat, bufferSize); }