survive dsound initialization failure

This commit is contained in:
zeromus 2012-03-02 03:39:09 +00:00
parent 49eb8272f9
commit e41f9d2a41
2 changed files with 24 additions and 20 deletions

View File

@ -19,8 +19,7 @@ namespace BizHawk.MultiClient
try { Global.DSound = new DirectSound(); }
catch
{
MessageBox.Show("Couldn't initialize DirectSound!", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
MessageBox.Show("Couldn't initialize DirectSound! Things may go poorly for you. Try changing your sound driver to 41khz instead of 48khz in mmsys.cpl.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try { Global.Direct3D = new Direct3D(); }

View File

@ -21,6 +21,8 @@ namespace BizHawk.MultiClient
private BufferedAsync semisync = new BufferedAsync();
public Sound(IntPtr handle, DirectSound device)
{
if (device != null)
{
device.SetCooperativeLevel(handle, CooperativeLevel.Priority);
@ -38,6 +40,7 @@ namespace BizHawk.MultiClient
desc.SizeInBytes = BufferSize;
DSoundBuffer = new SecondarySoundBuffer(device, desc);
ChangeVolume(Global.Config.SoundVolume);
}
SoundBuffer = new byte[BufferSize];
disposed = false;
@ -47,7 +50,7 @@ namespace BizHawk.MultiClient
{
if (disposed) throw new ObjectDisposedException("Sound");
if (Global.Config.SoundEnabled == false) return;
if (DSoundBuffer == null) return;
if (IsPlaying)
return;
@ -101,6 +104,8 @@ namespace BizHawk.MultiClient
int soundoffset;
int SNDDXGetAudioSpace()
{
if (DSoundBuffer == null) return 0;
int playcursor = DSoundBuffer.CurrentPlayPosition;
int writecursor = DSoundBuffer.CurrentWritePosition;