GUI: audio failure resilience

This commit is contained in:
tildearrow 2022-02-05 23:48:56 -05:00
parent fe47a2ba09
commit b0698dbac3
5 changed files with 35 additions and 11 deletions

View file

@ -5937,7 +5937,7 @@ void DivEngine::setConsoleMode(bool enable) {
consoleMode=enable;
}
void DivEngine::switchMaster() {
bool DivEngine::switchMaster() {
deinitAudioBackend();
quitDispatch();
initDispatch();
@ -5948,8 +5948,12 @@ void DivEngine::switchMaster() {
}
if (!output->setRun(true)) {
logE("error while activating audio!\n");
return false;
}
} else {
return false;
}
return true;
}
TAAudioDesc& DivEngine::getAudioDescWant() {
@ -6132,7 +6136,12 @@ bool DivEngine::init() {
loadConf();
// init the rest of engine
if (!initAudioBackend()) return false;
bool haveAudio=false;
if (!initAudioBackend()) {
logE("no audio output available!\n");
} else {
haveAudio=true;
}
samp_bb=blip_new(32768);
if (samp_bb==NULL) {
@ -6140,7 +6149,7 @@ bool DivEngine::init() {
return false;
}
samp_bbOut=new short[got.bufsize];
samp_bbOut=new short[32768];
samp_bbIn=new short[32768];
samp_bbInLen=32768;
@ -6162,9 +6171,13 @@ bool DivEngine::init() {
reset();
active=true;
if (!output->setRun(true)) {
logE("error while activating!\n");
if (!haveAudio) {
return false;
} else {
if (!output->setRun(true)) {
logE("error while activating!\n");
return false;
}
}
return true;
}

View file

@ -534,7 +534,7 @@ class DivEngine {
String getWarnings();
// switch master
void switchMaster();
bool switchMaster();
// get audio desc want
TAAudioDesc& getAudioDescWant();

View file

@ -3584,7 +3584,9 @@ void FurnaceGUI::commitSettings() {
e->saveConf();
e->switchMaster();
if (!e->switchMaster()) {
showError("could not initialize audio!");
}
ImGui::GetIO().Fonts->Clear();

View file

@ -397,9 +397,6 @@ class FurnaceGUI {
int load(String path);
void exportAudio(String path, DivAudioExportModes mode);
void showWarning(String what, FurnaceGUIWarnings type);
void showError(String what);
void applyUISettings();
void encodeMMLStr(String& target, int* macro, int macroLen, int macroLoop);
@ -411,6 +408,8 @@ class FurnaceGUI {
const char* getSystemName(DivSystem which);
public:
void showWarning(String what, FurnaceGUIWarnings type);
void showError(String what);
const char* noteName(short note, short octave);
bool decodeNote(const char* what, short& note, short& octave);
void bindEngine(DivEngine* eng);

View file

@ -38,6 +38,8 @@ bool consoleMode=false;
bool consoleMode=true;
#endif
bool displayEngineFailError=false;
std::vector<TAParam> params;
bool pHelp(String) {
@ -330,7 +332,11 @@ int main(int argc, char** argv) {
}
if (!e.init()) {
logE("could not initialize engine!\n");
return 1;
if (consoleMode) {
return 1;
} else {
displayEngineFailError=false;
}
}
if (outName!="" || vgmOutName!="") {
if (vgmOutName!="") {
@ -383,6 +389,10 @@ int main(int argc, char** argv) {
g.bindEngine(&e);
if (!g.init()) return 1;
if (displayEngineFailError) {
g.showError("error while initializing audio!");
}
if (!fileName.empty()) {
g.setFileName(fileName);
}