fix: make DirectSound work

This commit is contained in:
Anna 2022-08-22 14:35:56 -04:00
parent 5b017d322e
commit b3c0c0492a
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
3 changed files with 10 additions and 26 deletions

View File

@ -37,7 +37,9 @@ namespace PeepingTom {
public bool PlaySoundOnTarget { get; set; }
public string? SoundPath { get; set; }
public float SoundVolume { get; set; } = 1f;
[Obsolete("use new", true)]
public int SoundDevice { get; set; } = -1;
public Guid SoundDeviceNew { get; set; } = Guid.Empty;
public float SoundCooldown { get; set; } = 10f;
public bool PlaySoundWhenClosed { get; set; }

View File

@ -242,32 +242,17 @@ namespace PeepingTom {
}
var devices = DirectSoundOut.Devices.ToList();
var soundDevice = this.Plugin.Config.SoundDevice;
string name;
if (soundDevice == -1) {
name = Language.SettingsSoundDefaultDevice;
} else if (soundDevice > -1 && soundDevice < devices.Count) {
var info = devices[soundDevice];
name = info.ModuleName;
} else {
name = Language.SettingsSoundInvalidDevice;
}
var soundDevice = devices.FirstOrDefault(d => d.Guid == this.Plugin.Config.SoundDeviceNew);
var name = soundDevice != null ? soundDevice.Description : Language.SettingsSoundInvalidDevice;
if (ImGui.BeginCombo($"{Language.SettingsSoundOutputDevice}###sound-output-device-combo", name)) {
if (ImGui.Selectable(Language.SettingsSoundDefaultDevice)) {
this.Plugin.Config.SoundDevice = -1;
this.Plugin.Config.Save();
}
ImGui.Separator();
for (var deviceNum = 0; deviceNum < devices.Count; deviceNum++) {
var info = devices[deviceNum];
if (!ImGui.Selectable($"{info.ModuleName}##{deviceNum}")) {
if (!ImGui.Selectable($"{info.Description}##{deviceNum}")) {
continue;
}
this.Plugin.Config.SoundDevice = deviceNum;
this.Plugin.Config.SoundDeviceNew = info.Guid;
this.Plugin.Config.Save();
}

View File

@ -160,9 +160,9 @@ namespace PeepingTom {
}
private void PlaySound() {
var soundDevice = this.Plugin.Config.SoundDevice;
if (soundDevice < -1 || soundDevice >= DirectSoundOut.Devices.Count()) {
soundDevice = -1;
var soundDevice = DirectSoundOut.Devices.FirstOrDefault(d => d.Guid == this.Plugin.Config.SoundDeviceNew);
if (soundDevice == null) {
return;
}
new Thread(() => {
@ -172,7 +172,6 @@ namespace PeepingTom {
reader = new WaveFileReader(Resource.AsStream("Resources/target.wav"));
} else {
reader = new MediaFoundationReader(this.Plugin.Config.SoundPath);
}
} catch (Exception e) {
var error = string.Format(Language.SoundChatError, e.Message);
@ -186,9 +185,7 @@ namespace PeepingTom {
};
using (reader) {
var devices = DirectSoundOut.Devices.ToList();
var device = devices[soundDevice];
using var output = new DirectSoundOut(device.Guid);
using var output = new DirectSoundOut(soundDevice.Guid);
try {
output.Init(channel);