From b3fe92a4832b1be2f674ac9a3ce2cb51ef0bb6b4 Mon Sep 17 00:00:00 2001 From: LA <1245661240@qq.com> Date: Thu, 1 Jan 2026 12:42:40 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=9F=B3=E9=A2=91]=E4=BB=85ASIO=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=89=8D=E6=98=BE=E7=A4=BA=E9=87=87=E6=A0=B7=E7=8E=87?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LAsEzExtensions/Audio/AudioExtensions.cs | 6 ++-- .../Sections/Audio/AudioDevicesSettings.cs | 35 ++++--------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/osu.Game/LAsEzExtensions/Audio/AudioExtensions.cs b/osu.Game/LAsEzExtensions/Audio/AudioExtensions.cs index 277c1d26de..21142121e4 100644 --- a/osu.Game/LAsEzExtensions/Audio/AudioExtensions.cs +++ b/osu.Game/LAsEzExtensions/Audio/AudioExtensions.cs @@ -13,7 +13,7 @@ namespace osu.Game.LAsEzExtensions.Audio public static class AudioExtensions { // 固定采样率列表,优先使用48kHz - private static readonly int[] common_sample_rates = { 48000, 44100, 96000, 192000 }; + public static readonly int[] COMMON_SAMPLE_RATES = { 48000, 44100, 96000, 192000 }; // 扩展方法:获取当前采样率 public static int GetSampleRate(this AudioManager audioManager) @@ -43,7 +43,7 @@ namespace osu.Game.LAsEzExtensions.Audio { case AudioOutputMode.Asio: // 对于ASIO设备,返回固定的常见采样率列表,因为实际支持的采样率是从这些中选择的 - return common_sample_rates; + return COMMON_SAMPLE_RATES; case AudioOutputMode.WasapiExclusive: case AudioOutputMode.WasapiShared: @@ -56,7 +56,7 @@ namespace osu.Game.LAsEzExtensions.Audio catch { // 如果获取失败,返回默认列表 - return common_sample_rates; + return COMMON_SAMPLE_RATES; } } diff --git a/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs index cb8f0327dc..ad550c1661 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs @@ -50,7 +50,8 @@ namespace osu.Game.Overlays.Settings.Sections.Audio { LabelText = "ASIO Sample Rate(Testing)", Keywords = new[] { "sample", "rate", "frequency" }, - Current = new Bindable(48000), + Items = AudioExtensions.COMMON_SAMPLE_RATES, + Current = new Bindable(audio.GetSampleRate()), TooltipText = "48k is better, too high a value will cause delays and clock synchronization errors" }); Add(wasapiExperimental = new SettingsCheckbox @@ -67,7 +68,6 @@ namespace osu.Game.Overlays.Settings.Sections.Audio audio.OnNewDevice += onDeviceChanged; audio.OnLostDevice += onDeviceChanged; dropdown.Current = audio.AudioDevice; - sampleRateDropdown.Current.Value = audio.GetSampleRate(); sampleRateDropdown.Current.ValueChanged += e => audio.SetSampleRate(e.NewValue); // Setup ASIO sample rate synchronization @@ -144,40 +144,19 @@ namespace osu.Game.Overlays.Settings.Sections.Audio { Logger.Log($"[AudioDevicesSettings] Detected ASIO device: '{selectedDevice}'", LoggingTarget.Runtime, LogLevel.Debug); - // For ASIO devices, get the actual device name without the "(ASIO)" suffix - string asioDeviceName = selectedDevice.Replace(" (ASIO)", ""); - - // Get supported sample rates for this specific ASIO device - double[]? supportedRates = audio.GetAsioDeviceSupportedSampleRates(asioDeviceName); - - // Convert double array to int array for the dropdown - var newItems = supportedRates?.Select(rate => (int)rate).ToList() ?? new List(); - sampleRateDropdown.Items = newItems; - - // Ensure current sample rate is valid for this device + // For ASIO devices, ensure current sample rate is valid for the fixed list int currentRate = audio.GetSampleRate(); - if (forceSetCurrent && !newItems.Contains(currentRate) && newItems.Count > 0) + if (forceSetCurrent && !AudioExtensions.COMMON_SAMPLE_RATES.Contains(currentRate)) { // Set to first available rate if current rate is not supported - sampleRateDropdown.Current.Value = newItems[0]; + sampleRateDropdown.Current.Value = AudioExtensions.COMMON_SAMPLE_RATES[0]; } } else { - // For non-ASIO devices, use the existing method - var supportedRates = audio.GetSupportedSampleRates(selectedDevice); - var newItems = supportedRates.ToList(); - sampleRateDropdown.Items = newItems; - - // Ensure current sample rate is valid for this device - int currentRate = audio.GetSampleRate(); - - if (forceSetCurrent && !newItems.Contains(currentRate) && newItems.Count > 0) - { - // Set to first available rate if current rate is not supported - sampleRateDropdown.Current.Value = newItems[0]; - } + // For non-ASIO devices, no sample rate options + // Items is already set to COMMON_SAMPLE_RATES, but since hidden, no issue } }