refactor: try using directsound

This commit is contained in:
Anna 2022-08-22 14:14:11 -04:00
parent 4ffd7116ad
commit 5b017d322e
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
4 changed files with 27 additions and 92 deletions

View File

@ -53,7 +53,8 @@
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.7"/>
<PackageReference Include="Fody" Version="6.6.3" PrivateAssets="all"/>
<PackageReference Include="NAudio" Version="2.1.0"/>
<PackageReference Include="NAudio.Core" Version="2.1.0"/>
<PackageReference Include="NAudio.Wasapi" Version="2.1.0"/>
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
<PackageReference Include="XivCommon" Version="6.0.0"/>
</ItemGroup>

View File

@ -241,13 +241,14 @@ namespace PeepingTom {
this.Plugin.Config.Save();
}
var devices = DirectSoundOut.Devices.ToList();
var soundDevice = this.Plugin.Config.SoundDevice;
string name;
if (soundDevice == -1) {
name = Language.SettingsSoundDefaultDevice;
} else if (soundDevice > -1 && soundDevice < WaveOut.DeviceCount) {
var caps = WaveOut.GetCapabilities(soundDevice);
name = caps.ProductName;
} else if (soundDevice > -1 && soundDevice < devices.Count) {
var info = devices[soundDevice];
name = info.ModuleName;
} else {
name = Language.SettingsSoundInvalidDevice;
}
@ -260,9 +261,9 @@ namespace PeepingTom {
ImGui.Separator();
for (var deviceNum = 0; deviceNum < WaveOut.DeviceCount; deviceNum++) {
var caps = WaveOut.GetCapabilities(deviceNum);
if (!ImGui.Selectable(caps.ProductName)) {
for (var deviceNum = 0; deviceNum < devices.Count; deviceNum++) {
var info = devices[deviceNum];
if (!ImGui.Selectable($"{info.ModuleName}##{deviceNum}")) {
continue;
}

View File

@ -161,7 +161,7 @@ namespace PeepingTom {
private void PlaySound() {
var soundDevice = this.Plugin.Config.SoundDevice;
if (soundDevice < -1 || soundDevice > WaveOut.DeviceCount) {
if (soundDevice < -1 || soundDevice >= DirectSoundOut.Devices.Count()) {
soundDevice = -1;
}
@ -171,7 +171,8 @@ namespace PeepingTom {
if (this.Plugin.Config.SoundPath == null) {
reader = new WaveFileReader(Resource.AsStream("Resources/target.wav"));
} else {
reader = new AudioFileReader(this.Plugin.Config.SoundPath);
reader = new MediaFoundationReader(this.Plugin.Config.SoundPath);
}
} catch (Exception e) {
var error = string.Format(Language.SoundChatError, e.Message);
@ -185,9 +186,10 @@ namespace PeepingTom {
};
using (reader) {
using var output = new WaveOutEvent {
DeviceNumber = soundDevice,
};
var devices = DirectSoundOut.Devices.ToList();
var device = devices[soundDevice];
using var output = new DirectSoundOut(device.Guid);
try {
output.Init(channel);
output.Play();

View File

@ -14,18 +14,19 @@
"resolved": "6.6.3",
"contentHash": "X1WKKgSNYVtLzdO8dK3YWmfmljA4L0soePcWNouq9X6WbVF4bmivuJdlhTZx/2L3ml6tMvhFe8skIbVQ24PAYA=="
},
"NAudio": {
"NAudio.Core": {
"type": "Direct",
"requested": "[2.1.0, )",
"resolved": "2.1.0",
"contentHash": "iamDtIq4Tcq6BDEMatX7Wj6KI7rscECS72ZejjnL9RK8BgfrVRH2RlhlQVNxXNp9Up1eFESEiCILNBo7//Rr0g==",
"contentHash": "0iowfmolibU4KxjaC/s7lox/BeDg76UVvXtCuCzRiNpylVndqsxXxp+bVWFrpv0KzQDIKLxZrnDmYENlAI0u9g=="
},
"NAudio.Wasapi": {
"type": "Direct",
"requested": "[2.1.0, )",
"resolved": "2.1.0",
"contentHash": "Zp/8l79aYQEu7/HfzXWVpqyIwRUPgsvCj/Qx+pR6ykJxvwjqOoUfMiEG9US1wW4d7PEzT5ZBIL+cp90t6HNNiw==",
"dependencies": {
"NAudio.Asio": "2.1.0",
"NAudio.Core": "2.1.0",
"NAudio.Midi": "2.1.0",
"NAudio.Wasapi": "2.1.0",
"NAudio.WinForms": "2.1.0",
"NAudio.WinMM": "2.1.0"
"NAudio.Core": "2.1.0"
}
},
"Resourcer.Fody": {
@ -46,8 +47,8 @@
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
"resolved": "3.1.0",
"contentHash": "z7aeg8oHln2CuNulfhiLYxCVMPEwBl3rzicjvIX+4sUuCwvXw5oXQEtbiU2c0z4qYL5L3Kmx0mMA/+t/SbY67w=="
"resolved": "1.1.0",
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
},
"Microsoft.NETCore.Targets": {
"type": "Transitive",
@ -64,62 +65,6 @@
"System.Runtime": "4.3.0"
}
},
"Microsoft.Win32.Registry": {
"type": "Transitive",
"resolved": "4.7.0",
"contentHash": "KSrRMb5vNi0CWSGG1++id2ZOs/1QhRqROt+qgbEAdQuGjGrFcl4AOl4/exGPUYz2wUnU42nvJqon1T3U0kPXLA==",
"dependencies": {
"System.Security.AccessControl": "4.7.0",
"System.Security.Principal.Windows": "4.7.0"
}
},
"NAudio.Asio": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "YMXffgqPTsQIjmXYyzLrXSpQZzC7ZH49mmdXaPW3o/5S+AhFKZeOrwUA2fkvphQdGhryObbZnPAq+u8uABkH5A==",
"dependencies": {
"Microsoft.Win32.Registry": "4.7.0",
"NAudio.Core": "2.1.0"
}
},
"NAudio.Core": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "0iowfmolibU4KxjaC/s7lox/BeDg76UVvXtCuCzRiNpylVndqsxXxp+bVWFrpv0KzQDIKLxZrnDmYENlAI0u9g=="
},
"NAudio.Midi": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "m2ZunnyZ1p7OoAMh1scHRVle+GiFuIRrzkcxZJREUFHje8O2hcMGya3ZAjD+dV2FTcrbqNQUc4kJy9LOTuydUw==",
"dependencies": {
"NAudio.Core": "2.1.0"
}
},
"NAudio.Wasapi": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "Zp/8l79aYQEu7/HfzXWVpqyIwRUPgsvCj/Qx+pR6ykJxvwjqOoUfMiEG9US1wW4d7PEzT5ZBIL+cp90t6HNNiw==",
"dependencies": {
"NAudio.Core": "2.1.0"
}
},
"NAudio.WinForms": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "yoGCLidMVQmg66dNuEYusY1bttZJ5gxvufxRYFgxIw444dw4C70YsDgLeDugPd0rdwkSCQq5CtrVw6DSmxTxPA==",
"dependencies": {
"NAudio.WinMM": "2.1.0"
}
},
"NAudio.WinMM": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "lUU5C+XNzKhFUIEafA/nJpbtjksFtbUd033fs27KeHlOM0r6rQFF3l75dqxg+rWkGu81MfkBbYrNpH9p8qmtBA==",
"dependencies": {
"Microsoft.Win32.Registry": "4.7.0",
"NAudio.Core": "2.1.0"
}
},
"NETStandard.Library": {
"type": "Transitive",
"resolved": "1.6.1",
@ -745,15 +690,6 @@
"System.Runtime.Extensions": "4.3.0"
}
},
"System.Security.AccessControl": {
"type": "Transitive",
"resolved": "4.7.0",
"contentHash": "JECvTt5aFF3WT3gHpfofL2MNNP6v84sxtXxpqhLBCcDRzqsPBmHhQ6shv4DwwN2tRlzsUxtb3G9M3763rbXKDg==",
"dependencies": {
"Microsoft.NETCore.Platforms": "3.1.0",
"System.Security.Principal.Windows": "4.7.0"
}
},
"System.Security.Cryptography.Algorithms": {
"type": "Transitive",
"resolved": "4.3.0",
@ -898,11 +834,6 @@
"runtime.native.System.Security.Cryptography.OpenSsl": "4.3.0"
}
},
"System.Security.Principal.Windows": {
"type": "Transitive",
"resolved": "4.7.0",
"contentHash": "ojD0PX0XhneCsUbAZVKdb7h/70vyYMDYs85lwEI+LngEONe/17A0cFaRFqZU+sOEidcVswYWikYOQ9PPfjlbtQ=="
},
"System.Text.Encoding": {
"type": "Transitive",
"resolved": "4.3.0",