direct sound: you can now choose which of your devices to play out of. note that although you can make the change in the UI at any time, you actually have to restart the whole bizhawk to initialize on the new device.

This commit is contained in:
goyuken 2013-06-02 00:49:40 +00:00
parent 15bdff9ac8
commit 56d5d1ef5a
5 changed files with 70 additions and 15 deletions

View File

@ -436,6 +436,7 @@ namespace BizHawk.MultiClient
public bool MuteFrameAdvance = true;
public int SoundVolume = 100; //Range 0-100
public bool SoundThrottle = false;
public string SoundDevice = "";
// Log Window
public bool LogWindowSaveWindowPosition = true;

View File

@ -60,7 +60,7 @@ namespace BizHawk.MultiClient
Global.Config = ConfigService.Load<Config>(PathManager.DefaultIniPath, new Config());
#if WINDOWS
try { Global.DSound = new DirectSound(); }
try { Global.DSound = SoundEnumeration.Create(); }
catch
{
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);

View File

@ -1,5 +1,6 @@
using System;
using BizHawk.Emulation.Sound;
using System.Collections.Generic;
#if WINDOWS
using SlimDX.DirectSound;
using SlimDX.Multimedia;
@ -8,6 +9,30 @@ using SlimDX.Multimedia;
namespace BizHawk.MultiClient
{
#if WINDOWS
public static class SoundEnumeration
{
public static DirectSound Create()
{
var dc = DirectSound.GetDevices();
foreach (var dev in dc)
{
if (dev.Description == Global.Config.SoundDevice)
return new DirectSound(dev.DriverGuid);
}
return new DirectSound();
}
public static IEnumerable<string> DeviceNames()
{
var ret = new List<string>();
var dc = DirectSound.GetDevices();
foreach (var dev in dc)
ret.Add(dev.Description);
return ret;
}
}
public class Sound : IDisposable
{
public bool needDiscard;

View File

@ -36,6 +36,8 @@
this.SoundVolBar = new System.Windows.Forms.TrackBar();
this.SoundVolNumeric = new System.Windows.Forms.NumericUpDown();
this.ThrottlecheckBox = new System.Windows.Forms.CheckBox();
this.listBoxSoundDevices = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.SoundVolGroup.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.SoundVolBar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).BeginInit();
@ -45,7 +47,7 @@
//
this.Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Cancel.Location = new System.Drawing.Point(200, 209);
this.Cancel.Location = new System.Drawing.Point(317, 209);
this.Cancel.Name = "Cancel";
this.Cancel.Size = new System.Drawing.Size(75, 23);
this.Cancel.TabIndex = 0;
@ -57,7 +59,7 @@
//
this.OK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.OK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.OK.Location = new System.Drawing.Point(119, 209);
this.OK.Location = new System.Drawing.Point(236, 209);
this.OK.Name = "OK";
this.OK.Size = new System.Drawing.Size(75, 23);
this.OK.TabIndex = 1;
@ -67,7 +69,6 @@
//
// SoundOnCheckBox
//
this.SoundOnCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.SoundOnCheckBox.AutoSize = true;
this.SoundOnCheckBox.Location = new System.Drawing.Point(147, 12);
this.SoundOnCheckBox.Name = "SoundOnCheckBox";
@ -79,7 +80,6 @@
//
// MuteFrameAdvance
//
this.MuteFrameAdvance.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.MuteFrameAdvance.AutoSize = true;
this.MuteFrameAdvance.Location = new System.Drawing.Point(147, 35);
this.MuteFrameAdvance.Name = "MuteFrameAdvance";
@ -129,13 +129,35 @@
this.ThrottlecheckBox.Text = "Sound Throttle";
this.ThrottlecheckBox.UseVisualStyleBackColor = true;
//
// listBoxSoundDevices
//
this.listBoxSoundDevices.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listBoxSoundDevices.FormattingEnabled = true;
this.listBoxSoundDevices.Location = new System.Drawing.Point(108, 108);
this.listBoxSoundDevices.Name = "listBoxSoundDevices";
this.listBoxSoundDevices.Size = new System.Drawing.Size(284, 95);
this.listBoxSoundDevices.TabIndex = 6;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(108, 92);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(78, 13);
this.label1.TabIndex = 7;
this.label1.Text = "Sound Device:";
//
// SoundConfig
//
this.AcceptButton = this.OK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.Cancel;
this.ClientSize = new System.Drawing.Size(287, 244);
this.ClientSize = new System.Drawing.Size(404, 244);
this.Controls.Add(this.label1);
this.Controls.Add(this.listBoxSoundDevices);
this.Controls.Add(this.ThrottlecheckBox);
this.Controls.Add(this.SoundVolGroup);
this.Controls.Add(this.MuteFrameAdvance);
@ -166,5 +188,7 @@
private System.Windows.Forms.NumericUpDown SoundVolNumeric;
private System.Windows.Forms.TrackBar SoundVolBar;
private System.Windows.Forms.CheckBox ThrottlecheckBox;
private System.Windows.Forms.ListBox listBoxSoundDevices;
private System.Windows.Forms.Label label1;
}
}

View File

@ -25,15 +25,19 @@ namespace BizHawk.MultiClient
SoundVolNumeric.Value = Global.Config.SoundVolume;
UpdateSoundDialog();
// to be removed
//if (MainForm.INTERIM)
//{
// ThrottlecheckBox.Visible = true;
//}
//else
//{
ThrottlecheckBox.Visible = false;
//}
// vestigal
ThrottlecheckBox.Visible = false;
var dd = SoundEnumeration.DeviceNames();
listBoxSoundDevices.Items.Add("<default>");
listBoxSoundDevices.SelectedIndex = 0;
foreach (var d in dd)
{
listBoxSoundDevices.Items.Add(d);
if (d == Global.Config.SoundDevice)
listBoxSoundDevices.SelectedItem = d;
}
}
private void OK_Click(object sender, EventArgs e)
@ -42,6 +46,7 @@ namespace BizHawk.MultiClient
Global.Config.MuteFrameAdvance = MuteFrameAdvance.Checked;
Global.Config.SoundVolume = SoundVolBar.Value;
Global.Config.SoundThrottle = ThrottlecheckBox.Checked;
Global.Config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? "<default>";
Global.Sound.ChangeVolume(Global.Config.SoundVolume);
Global.Sound.UpdateSoundSettings();
Global.Sound.StartSound();