Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYunPlayer committed Jun 13, 2024
2 parents 5d46d48 + 63d1e8b commit adbb4a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 11 additions & 5 deletions TuneLab/Audio/SDL2/SDLAudioEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void Play()
// 如果没有打开音频设备那么打开第一个音频设备
if (_d.curDevId == 0)
{
SwitchDevice(0);
SwitchDevice(-1);
}

_d.start();
Expand Down Expand Up @@ -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 _,
Expand All @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions TuneLab/Audio/SDL2/SDLPlaybackData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public enum PlaybackState
// 播放信息
public string driver = "";

public int devNum = -1;

public PlaybackState state = PlaybackState.Stopped;

public ISampleProvider? sampleProvider = null;
Expand Down

0 comments on commit adbb4a5

Please sign in to comment.