Skip to content

Commit 30a1c46

Browse files
authored
Merge pull request #726 from nicolasnoble/safe-mode-miniaudio
Safe mode also uses Null Miniaudio driver.
2 parents 66713e9 + 7cb2544 commit 30a1c46

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

src/core/system.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ DstTP ClockCast(const SrcTP tp) {
5353
}
5454

5555
namespace Events {
56-
struct SettingsLoaded {};
56+
struct SettingsLoaded {
57+
bool safe = false;
58+
};
5759
struct Quitting {};
5860
struct LogMessage {
5961
LogClass logClass;

src/gui/gui.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ end)(jit.status()))
306306
auto& emuSettings = PCSX::g_emulator->settings;
307307
auto& debugSettings = emuSettings.get<Emulator::SettingDebugSettings>();
308308
json j;
309-
if (cfg.is_open() && !m_args.get<bool>("safe")) {
309+
bool safeMode = m_args.get<bool>("safe").value_or(false);
310+
if (cfg.is_open() && !safeMode) {
310311
try {
311312
cfg >> j;
312313
} catch (...) {
@@ -370,7 +371,7 @@ end)(jit.status()))
370371

371372
g_system->activateLocale(emuSettings.get<PCSX::Emulator::SettingLocale>());
372373

373-
g_system->m_eventBus->signal(Events::SettingsLoaded{});
374+
g_system->m_eventBus->signal(Events::SettingsLoaded{safeMode});
374375

375376
std::filesystem::path isoToOpen = m_args.get<std::string>("iso", "");
376377
if (!isoToOpen.empty()) PCSX::g_emulator->m_cdrom->m_iso.setIsoPath(isoToOpen);

src/spu/miniaudio.cc

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ PCSX::SPU::MiniAudio::MiniAudio(PCSX::SPU::SettingsType& settings)
5454
throw std::runtime_error("Unable to stop NULL audio device");
5555
};
5656
});
57-
m_listener.listen<Events::SettingsLoaded>([this](const auto& event) { init(); });
57+
m_listener.listen<Events::SettingsLoaded>([this](const auto& event) { init(event.safe); });
5858
}
5959

60-
void PCSX::SPU::MiniAudio::init() {
60+
void PCSX::SPU::MiniAudio::init(bool safe) {
6161
// First, initialize NULL device
6262
ma_backend nullContext = ma_backend_null;
6363
if (ma_context_init(&nullContext, 1, NULL, &m_contextNull) != MA_SUCCESS) {
@@ -84,20 +84,26 @@ void PCSX::SPU::MiniAudio::init() {
8484
// Then probe for actual device, and initialize it
8585
ma_backend backends[ma_backend_null + 1];
8686
unsigned count = 0;
87-
bool found = false;
88-
for (unsigned i = 0; i <= ma_backend_null; i++) {
89-
ma_backend b = ma_backend(i);
90-
if (!ma_is_backend_enabled(b)) continue;
91-
backends[count++] = b;
92-
if (ma_get_backend_name(b) == m_settings.get<Backend>().value) {
93-
found = true;
94-
count = 1;
95-
backends[0] = b;
96-
break;
87+
if (safe) {
88+
backends[0] = ma_backend_null;
89+
count = 1;
90+
m_settings.get<Backend>().value = ma_get_backend_name(ma_backend_null);
91+
} else {
92+
bool found = false;
93+
for (unsigned i = 0; i <= ma_backend_null; i++) {
94+
ma_backend b = ma_backend(i);
95+
if (!ma_is_backend_enabled(b)) continue;
96+
backends[count++] = b;
97+
if (ma_get_backend_name(b) == m_settings.get<Backend>().value) {
98+
found = true;
99+
count = 1;
100+
backends[0] = b;
101+
break;
102+
}
103+
}
104+
if (!found) {
105+
m_settings.get<Backend>().reset();
97106
}
98-
}
99-
if (!found) {
100-
m_settings.get<Backend>().reset();
101107
}
102108
if (ma_context_init(backends, count, NULL, &m_context) != MA_SUCCESS) {
103109
throw std::runtime_error("Error initializing miniaudio context");

src/spu/miniaudio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MiniAudio {
118118
SettingsType& m_settings;
119119
void callback(ma_device* device, float* output, ma_uint32 frameCount);
120120
void callbackNull(ma_device* device, float* output, ma_uint32 frameCount);
121-
void init();
121+
void init(bool safe = false);
122122
void uninit();
123123

124124
ma_context m_context;

0 commit comments

Comments
 (0)