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

View File

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

View File

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

View File

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