Clean up some dumb in *SoundOutput ctors
This commit is contained in:
parent
9e5ab0706e
commit
edda120b07
|
@ -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()
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue