diff --git a/Project-Aurora/Project-Aurora/Profiles/LocalPCInformation.cs b/Project-Aurora/Project-Aurora/Profiles/LocalPCInformation.cs index 675e6c2d8..101625a16 100644 --- a/Project-Aurora/Project-Aurora/Profiles/LocalPCInformation.cs +++ b/Project-Aurora/Project-Aurora/Profiles/LocalPCInformation.cs @@ -1,6 +1,7 @@ using Aurora.Utils; using NAudio.CoreAudioApi; using System.Linq; +using System.Runtime.InteropServices; namespace Aurora.Profiles { /// @@ -48,7 +49,8 @@ private MMDevice CaptureDevice { private MMDevice RenderDevice { get { - renderProxy.DeviceId = Global.Configuration.GSIAudioRenderDevice; + if (renderProxy != null) + renderProxy.DeviceId = Global.Configuration.GSIAudioRenderDevice; return renderProxy?.Device; } } @@ -150,9 +152,16 @@ private MMDevice RenderDevice { static LocalPCInformation() { // Do not create a capture device if audio capture is disabled. Otherwise it will create a mic icon in win 10 and people will think we're spies. - if (Global.Configuration.EnableAudioCapture) - captureProxy = new AudioDeviceProxy(Global.Configuration.GSIAudioCaptureDevice, DataFlow.Capture); - renderProxy = new AudioDeviceProxy(Global.Configuration.GSIAudioRenderDevice, DataFlow.Render); + try + { + if (Global.Configuration.EnableAudioCapture) + captureProxy = new AudioDeviceProxy(Global.Configuration.GSIAudioCaptureDevice, DataFlow.Capture); + renderProxy = new AudioDeviceProxy(Global.Configuration.GSIAudioRenderDevice, DataFlow.Render); + } + catch(COMException e) + { + Global.logger.Error("Error initializing audio device proxy in LocalPCInfo, this is probably caused by an incompatible audio software: " + e); + } } } diff --git a/Project-Aurora/Project-Aurora/Settings/Configuration.cs b/Project-Aurora/Project-Aurora/Settings/Configuration.cs index 9ed26a8a6..5090dffd6 100755 --- a/Project-Aurora/Project-Aurora/Settings/Configuration.cs +++ b/Project-Aurora/Project-Aurora/Settings/Configuration.cs @@ -497,7 +497,7 @@ public class Configuration : INotifyPropertyChanged public float idle_frequency; //Hardware Monitor - public int HardwareMonitorUpdateRate; + public int HardwareMonitorUpdateRate { get; set; } = 300; public VariableRegistry VarRegistry; @@ -579,8 +579,6 @@ public Configuration() idle_amount = 5; idle_frequency = 2.5f; - HardwareMonitorUpdateRate = 200; - //Debug BitmapDebugTopMost = false; HttpDebugTopMost = false; diff --git a/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml b/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml index 239bc8501..c954ba8cb 100755 --- a/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml +++ b/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml @@ -130,7 +130,7 @@ - + @@ -178,6 +178,10 @@ + + + + diff --git a/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml.cs b/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml.cs index 9783afa0d..2b87647a1 100755 --- a/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml.cs +++ b/Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml.cs @@ -952,9 +952,9 @@ private void startDelayAmount_ValueChanged(object sender, RoutedPropertyChangedE private void btnDumpSensors_Click(object sender, RoutedEventArgs e) { if (HardwareMonitor.TryDump()) - Xceed.Wpf.Toolkit.MessageBox.Show("Successfully wrote sensor info to logs folder"); + System.Windows.MessageBox.Show("Successfully wrote sensor info to logs folder"); else - Xceed.Wpf.Toolkit.MessageBox.Show("Eror dumping file. Consult log for details."); + System.Windows.MessageBox.Show("Eror dumping file. Consult log for details."); } } } diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/AmbilightLayerHandler.cs b/Project-Aurora/Project-Aurora/Settings/Layers/AmbilightLayerHandler.cs index 3110dd8c7..74069f507 100644 --- a/Project-Aurora/Project-Aurora/Settings/Layers/AmbilightLayerHandler.cs +++ b/Project-Aurora/Project-Aurora/Settings/Layers/AmbilightLayerHandler.cs @@ -346,7 +346,7 @@ public override EffectLayer Render(IGameState gamestate) break; case AmbilightType.AverageColor: - var average = BitmapUtils.GetAverageColor(screen); + var average = BitmapUtils.GetRegionColor(screen, cropRegion); if (Properties.BrightenImage) average = ColorUtils.ChangeBrightness(average, Properties.BrightnessChange); diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/Control_EqualizerLayer.xaml b/Project-Aurora/Project-Aurora/Settings/Layers/Control_EqualizerLayer.xaml index e140026a6..c7e8788aa 100644 --- a/Project-Aurora/Project-Aurora/Settings/Layers/Control_EqualizerLayer.xaml +++ b/Project-Aurora/Project-Aurora/Settings/Layers/Control_EqualizerLayer.xaml @@ -1,15 +1,4 @@ - + @@ -17,7 +6,7 @@ - + @@ -27,7 +16,7 @@ - + @@ -37,7 +26,7 @@ - + @@ -45,53 +34,120 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/EqualizerLayerHandler.cs b/Project-Aurora/Project-Aurora/Settings/Layers/EqualizerLayerHandler.cs index 95705e033..8d3e1197a 100644 --- a/Project-Aurora/Project-Aurora/Settings/Layers/EqualizerLayerHandler.cs +++ b/Project-Aurora/Project-Aurora/Settings/Layers/EqualizerLayerHandler.cs @@ -13,6 +13,8 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; +using System.Runtime.InteropServices; +using System.ServiceModel.Configuration; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -175,6 +177,8 @@ private AudioDeviceProxy DeviceProxy { private float[] previous_freq_results = null; + private bool first = true; + public EqualizerLayerHandler() { _ffts = new Complex[fftLength]; @@ -193,11 +197,34 @@ public override EffectLayer Render(IGameState gamestate) { try { + //this initialization has to be done on this method + //because of threading issues with the NAudio stuff. + //it should only be done once, so we set this bool to true right after. + //should prevent the layer from spamming the log with errors and throwing + //exceptions left and right if the users has nahimic drivers installed + if (first) + { + try + { + DeviceProxy.DeviceId = Properties.DeviceId; + } + catch (COMException e) + { + Global.logger.Error("Error binding to audio device in the audio visualizer layer. This is probably caused by an incompatibility with audio software: " + e); + } + first = false; + } + + EffectLayer equalizer_layer = new EffectLayer(); + + if (deviceProxy is null) + return equalizer_layer; + // Update device ID. If it has changed, it will re-assign itself to the new device DeviceProxy.DeviceId = Properties.DeviceId; // The system sound as a value between 0.0 and 1.0 - float system_sound_normalized = DeviceProxy.Device?.AudioEndpointVolume.MasterVolumeLevelScalar ?? 1f; + float system_sound_normalized = DeviceProxy.Device?.AudioMeterInformation?.MasterPeakValue ?? 1f; // Scale the Maximum amplitude with the system sound if enabled, so that at 100% volume the max_amp is unchanged. // Replaces all Properties.MaxAmplitude calls with the scaled value @@ -214,8 +241,6 @@ public override EffectLayer Render(IGameState gamestate) Complex[] _local_fft = new List(_ffts).ToArray(); Complex[] _local_fft_previous = new List(_ffts_prev).ToArray(); - EffectLayer equalizer_layer = new EffectLayer(); - bool BgEnabled = false; switch (Properties.BackgroundMode) { @@ -419,7 +444,7 @@ private Brush GetBrush(float value, float position, float max_position) public override void Dispose() { - DeviceProxy?.Dispose(); + deviceProxy?.Dispose(); deviceProxy = null; } } diff --git a/Project-Aurora/Project-Aurora/Utils/HardwareMonitor.cs b/Project-Aurora/Project-Aurora/Utils/HardwareMonitor.cs index 537321b20..6bb5b2436 100644 --- a/Project-Aurora/Project-Aurora/Utils/HardwareMonitor.cs +++ b/Project-Aurora/Project-Aurora/Utils/HardwareMonitor.cs @@ -77,7 +77,7 @@ public static bool TryDump() private static ISensor FindSensor(this IHardware hardware, string identifier) { - var result = Array.Find(hardware.Sensors, s => s.Identifier.ToString().Contains(identifier)); + var result = hardware.Sensors.OrderBy(s => s.Identifier).FirstOrDefault(s => s.Identifier.ToString().Contains(identifier)); if (result is null) { Global.logger.Error( @@ -88,7 +88,7 @@ private static ISensor FindSensor(this IHardware hardware, string identifier) private static ISensor FindSensor(this IHardware hardware, SensorType type) { - var result = Array.Find(hardware.Sensors, s => s.SensorType == type); + var result = hardware.Sensors.OrderBy(s => s.Identifier).FirstOrDefault(s => s.SensorType == type); if (result is null) { Global.logger.Error( @@ -119,7 +119,9 @@ protected HardwareUpdater() _updateTimer.Elapsed += (a, b) => { if (inUse) - hw.Update(); + hw?.Update(); + if (_updateTimer.Interval != Global.Configuration.HardwareMonitorUpdateRate) + _updateTimer.Interval = Global.Configuration.HardwareMonitorUpdateRate; }; _updateTimer.Start(); } @@ -129,14 +131,8 @@ protected float GetValue(ISensor sensor) inUse = true; _useTimer.Stop(); _useTimer.Start(); - return sensor?.Value ?? 0; - } - public void SetUpdateTimer(int interval) - { - _updateTimer.Interval = interval; - _updateTimer.Stop(); - _updateTimer.Start(); + return sensor?.Value ?? 0; } }