From b693368c9cacdffaec78d350bbc816b0b1c4ed58 Mon Sep 17 00:00:00 2001 From: Sine Striker Date: Fri, 14 Jun 2024 00:53:57 +0800 Subject: [PATCH] SDL: Open current device at default --- TuneLab/Audio/SDL2/SDLAudioEngine.cs | 16 +++++++++++----- TuneLab/Audio/SDL2/SDLPlaybackData.cs | 2 -- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/TuneLab/Audio/SDL2/SDLAudioEngine.cs b/TuneLab/Audio/SDL2/SDLAudioEngine.cs index 668b2c9..e043fea 100644 --- a/TuneLab/Audio/SDL2/SDLAudioEngine.cs +++ b/TuneLab/Audio/SDL2/SDLAudioEngine.cs @@ -110,7 +110,7 @@ public void Play() // 如果没有打开音频设备那么打开第一个音频设备 if (_d.curDevId == 0) { - SwitchDevice(0); + SwitchDevice(-1); } _d.start(); @@ -154,12 +154,11 @@ public void SwitchDevice(int deviceNumber) return; } - _d.devNum = deviceNumber; - // 打开音频设备 uint id; + string? deviceToOpen = deviceNumber < 0 ? null : SDL.SDL_GetAudioDeviceName(deviceNumber, 0); if ((id = SDL.SDL_OpenAudioDevice( - SDL.SDL_GetAudioDeviceName(_d.devNum, 0), + deviceToOpen, 0, ref _d.spec, out _, @@ -168,7 +167,14 @@ public void SwitchDevice(int deviceNumber) throw new IOException($"SDLPlayback: Failed to open audio device: {SDL.SDL_GetError()}."); } - Console.WriteLine($"SDLPlayback: {SDL.SDL_GetAudioDeviceName(_d.devNum, 0)}"); + if (deviceToOpen == null) + { + Console.WriteLine($"SDLPlayback: Current Device"); + } + else + { + Console.WriteLine($"SDLPlayback: {deviceToOpen}"); + } _d.setDevId(id); } diff --git a/TuneLab/Audio/SDL2/SDLPlaybackData.cs b/TuneLab/Audio/SDL2/SDLPlaybackData.cs index 32cb6c3..41d1ad5 100644 --- a/TuneLab/Audio/SDL2/SDLPlaybackData.cs +++ b/TuneLab/Audio/SDL2/SDLPlaybackData.cs @@ -25,8 +25,6 @@ public enum PlaybackState // 播放信息 public string driver = ""; - public int devNum = -1; - public PlaybackState state = PlaybackState.Stopped; public ISampleProvider? sampleProvider = null;