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(); }
@ -41,9 +40,9 @@ namespace BizHawk.MultiClient
else
{
var mf = new MainForm(args);
var title = mf.Text;
mf.Show();
mf.Text = title;
var title = mf.Text;
mf.Show();
mf.Text = title;
mf.ProgramRunLoop();
}
}

View File

@ -22,22 +22,25 @@ namespace BizHawk.MultiClient
public Sound(IntPtr handle, DirectSound device)
{
device.SetCooperativeLevel(handle, CooperativeLevel.Priority);
if (device != null)
{
device.SetCooperativeLevel(handle, CooperativeLevel.Priority);
var format = new WaveFormat();
format.SamplesPerSecond = 44100;
format.BitsPerSample = 16;
format.Channels = 2;
format.FormatTag = WaveFormatTag.Pcm;
format.BlockAlignment = 4;
format.AverageBytesPerSecond = format.SamplesPerSecond * format.Channels * (format.BitsPerSample / 8);
var format = new WaveFormat();
format.SamplesPerSecond = 44100;
format.BitsPerSample = 16;
format.Channels = 2;
format.FormatTag = WaveFormatTag.Pcm;
format.BlockAlignment = 4;
format.AverageBytesPerSecond = format.SamplesPerSecond * format.Channels * (format.BitsPerSample / 8);
var desc = new SoundBufferDescription();
desc.Format = format;
desc.Flags = BufferFlags.GlobalFocus | BufferFlags.Software | BufferFlags.GetCurrentPosition2 | BufferFlags.ControlVolume;
desc.SizeInBytes = BufferSize;
DSoundBuffer = new SecondarySoundBuffer(device, desc);
ChangeVolume(Global.Config.SoundVolume);
var desc = new SoundBufferDescription();
desc.Format = format;
desc.Flags = BufferFlags.GlobalFocus | BufferFlags.Software | BufferFlags.GetCurrentPosition2 | BufferFlags.ControlVolume;
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;