fix: make DirectSound work
This commit is contained in:
parent
5b017d322e
commit
b3c0c0492a
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue