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(); } try { Global.DSound = new DirectSound(); }
catch catch
{ {
MessageBox.Show("Couldn't initialize DirectSound!", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 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);
return;
} }
try { Global.Direct3D = new Direct3D(); } try { Global.Direct3D = new Direct3D(); }
@ -41,9 +40,9 @@ namespace BizHawk.MultiClient
else else
{ {
var mf = new MainForm(args); var mf = new MainForm(args);
var title = mf.Text; var title = mf.Text;
mf.Show(); mf.Show();
mf.Text = title; mf.Text = title;
mf.ProgramRunLoop(); mf.ProgramRunLoop();
} }
} }

View File

@ -22,22 +22,25 @@ namespace BizHawk.MultiClient
public Sound(IntPtr handle, DirectSound device) public Sound(IntPtr handle, DirectSound device)
{ {
device.SetCooperativeLevel(handle, CooperativeLevel.Priority); if (device != null)
{
device.SetCooperativeLevel(handle, CooperativeLevel.Priority);
var format = new WaveFormat(); var format = new WaveFormat();
format.SamplesPerSecond = 44100; format.SamplesPerSecond = 44100;
format.BitsPerSample = 16; format.BitsPerSample = 16;
format.Channels = 2; format.Channels = 2;
format.FormatTag = WaveFormatTag.Pcm; format.FormatTag = WaveFormatTag.Pcm;
format.BlockAlignment = 4; format.BlockAlignment = 4;
format.AverageBytesPerSecond = format.SamplesPerSecond * format.Channels * (format.BitsPerSample / 8); format.AverageBytesPerSecond = format.SamplesPerSecond * format.Channels * (format.BitsPerSample / 8);
var desc = new SoundBufferDescription(); var desc = new SoundBufferDescription();
desc.Format = format; desc.Format = format;
desc.Flags = BufferFlags.GlobalFocus | BufferFlags.Software | BufferFlags.GetCurrentPosition2 | BufferFlags.ControlVolume; desc.Flags = BufferFlags.GlobalFocus | BufferFlags.Software | BufferFlags.GetCurrentPosition2 | BufferFlags.ControlVolume;
desc.SizeInBytes = BufferSize; desc.SizeInBytes = BufferSize;
DSoundBuffer = new SecondarySoundBuffer(device, desc); DSoundBuffer = new SecondarySoundBuffer(device, desc);
ChangeVolume(Global.Config.SoundVolume); ChangeVolume(Global.Config.SoundVolume);
}
SoundBuffer = new byte[BufferSize]; SoundBuffer = new byte[BufferSize];
disposed = false; disposed = false;
@ -47,7 +50,7 @@ namespace BizHawk.MultiClient
{ {
if (disposed) throw new ObjectDisposedException("Sound"); if (disposed) throw new ObjectDisposedException("Sound");
if (Global.Config.SoundEnabled == false) return; if (Global.Config.SoundEnabled == false) return;
if (DSoundBuffer == null) return;
if (IsPlaying) if (IsPlaying)
return; return;
@ -101,6 +104,8 @@ namespace BizHawk.MultiClient
int soundoffset; int soundoffset;
int SNDDXGetAudioSpace() int SNDDXGetAudioSpace()
{ {
if (DSoundBuffer == null) return 0;
int playcursor = DSoundBuffer.CurrentPlayPosition; int playcursor = DSoundBuffer.CurrentPlayPosition;
int writecursor = DSoundBuffer.CurrentWritePosition; int writecursor = DSoundBuffer.CurrentWritePosition;