Clean up some dumb in *SoundOutput ctors

This commit is contained in:
YoshiRulz 2020-11-22 11:48:17 +10:00
parent 9e5ab0706e
commit edda120b07
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 18 additions and 17 deletions

View File

@ -20,16 +20,19 @@ namespace BizHawk.Bizware.DirectX
private BufferPool _bufferPool;
private long _runningSamplesQueued;
public XAudio2SoundOutput(IHostAudioManager sound)
public XAudio2SoundOutput(IHostAudioManager sound, string chosenDeviceName)
{
_sound = sound;
_device = new XAudio2();
int? deviceIndex = Enumerable.Range(0, _device.DeviceCount)
.Select(n => (int?)n)
.FirstOrDefault(n => _device.GetDeviceDetails(n.Value).DisplayName == _sound.ConfigDevice);
_masteringVoice = deviceIndex == null ?
new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate) :
new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate, deviceIndex.Value);
for (int i = 0, l = _device.DeviceCount; i < l; i++)
{
if (_device.GetDeviceDetails(i).DisplayName == chosenDeviceName)
{
_masteringVoice = new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate, i);
return;
}
}
_masteringVoice = new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate);
}
public void Dispose()

View File

@ -10,8 +10,6 @@ namespace BizHawk.Client.Common
int ConfigBufferSizeMs { get; }
string ConfigDevice { get; }
int SampleRate { get; }
void HandleInitializationOrUnderrun(bool isUnderrun, ref int samplesNeeded);

View File

@ -19,11 +19,13 @@ namespace BizHawk.Client.EmuHawk
private int _currentSamplesQueued;
private short[] _tempSampleBuffer;
public OpenALSoundOutput(IHostAudioManager sound)
public OpenALSoundOutput(IHostAudioManager sound, string chosenDeviceName)
{
_sound = sound;
string deviceName = GetDeviceNames().FirstOrDefault(n => n == _sound.ConfigDevice);
_context = new AudioContext(deviceName, _sound.SampleRate);
_context = new AudioContext(
GetDeviceNames().Contains(chosenDeviceName) ? chosenDeviceName : null,
_sound.SampleRate
);
}
public void Dispose()

View File

@ -27,8 +27,6 @@ namespace BizHawk.Client.EmuHawk
public int ConfigBufferSizeMs => GlobalWin.Config.SoundBufferSizeMs;
public string ConfigDevice => GlobalWin.Config.SoundDevice;
public Sound(IntPtr mainWindowHandle)
{
BlockAlign = BytesPerSample * ChannelCount;
@ -38,15 +36,15 @@ namespace BizHawk.Client.EmuHawk
// if DirectSound or XAudio is chosen, use OpenAL, otherwise comply with the user's choice
_outputDevice = GlobalWin.Config.SoundOutputMethod == ESoundOutputMethod.Dummy
? (ISoundOutput) new DummySoundOutput(this)
: new OpenALSoundOutput(this);
: new OpenALSoundOutput(this, GlobalWin.Config.SoundDevice);
}
else
{
_outputDevice = GlobalWin.Config.SoundOutputMethod switch
{
ESoundOutputMethod.DirectSound => new DirectSoundSoundOutput(this, mainWindowHandle, GlobalWin.Config.SoundDevice),
ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this),
ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this),
ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this, GlobalWin.Config.SoundDevice),
ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this, GlobalWin.Config.SoundDevice),
_ => new DummySoundOutput(this)
};
}