mirror of
https://github.com/SK-la/Ez2Lazer.git
synced 2026-03-13 11:20:28 +00:00
[音频]仅ASIO设备才显示采样率设置
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
|
||||
{
|
||||
LabelText = "ASIO Sample Rate(Testing)",
|
||||
Keywords = new[] { "sample", "rate", "frequency" },
|
||||
Current = new Bindable<int>(48000),
|
||||
Items = AudioExtensions.COMMON_SAMPLE_RATES,
|
||||
Current = new Bindable<int>(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<int>();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user