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

View file

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

View file

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

View file

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

View file

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