improve low-latency mode strategy

This commit is contained in:
tildearrow 2022-04-15 14:38:25 -05:00
parent eb70086234
commit 45460df96d
4 changed files with 25 additions and 15 deletions

View File

@ -2237,6 +2237,8 @@ bool DivEngine::initAudioBackend() {
if (metroVol<0.0f) metroVol=0.0f;
if (metroVol>2.0f) metroVol=2.0f;
if (lowLatency) logI("using low latency mode.");
switch (audioEngine) {
case DIV_AUDIO_JACK:
#ifndef HAVE_JACK

View File

@ -21,14 +21,19 @@
#include "instrument.h"
#include "engine.h"
void DivMacroStruct::doMacro(DivInstrumentMacro& source, bool released) {
void DivMacroStruct::doMacro(DivInstrumentMacro& source, bool released, bool tick) {
if (!tick) {
had=false;
return;
}
if (finished) {
finished=false;
}
if (had!=has) {
if (actualHad!=has) {
finished=true;
}
had=has;
actualHad=has;
had=actualHad;
if (has) {
val=source.val[pos++];
if (source.rel>=0 && pos>source.rel && !released) {
@ -52,17 +57,18 @@ void DivMacroInt::next() {
if (ins==NULL) return;
// run macros
// TODO: potentially get rid of list to avoid allocations
if (--subTick<=0) {
subTick--;
for (size_t i=0; i<macroListLen; i++) {
if (macroList[i]!=NULL && macroSource[i]!=NULL) {
macroList[i]->doMacro(*macroSource[i],released,subTick==0);
}
}
if (subTick<=0) {
if (e==NULL) {
subTick=1;
} else {
subTick=e->tickMult;
}
for (size_t i=0; i<macroListLen; i++) {
if (macroList[i]!=NULL && macroSource[i]!=NULL) {
macroList[i]->doMacro(*macroSource[i],released);
}
}
}
}
@ -85,6 +91,7 @@ void DivMacroInt::init(DivInstrument* which) {
if (macroList[i]!=NULL) macroList[i]->init();
}
macroListLen=0;
subTick=1;
released=false;

View File

@ -27,17 +27,17 @@ class DivEngine;
struct DivMacroStruct {
int pos;
int val;
bool has, had, finished, will;
bool has, had, actualHad, finished, will;
unsigned int mode;
void doMacro(DivInstrumentMacro& source, bool released);
void doMacro(DivInstrumentMacro& source, bool released, bool tick);
void init() {
pos=mode=0;
has=had=will=false;
has=had=actualHad=will=false;
// TODO: test whether this breaks anything?
val=0;
}
void prepare(DivInstrumentMacro& source) {
has=had=will=true;
has=had=actualHad=will=true;
mode=source.mode;
}
DivMacroStruct():
@ -45,6 +45,7 @@ struct DivMacroStruct {
val(0),
has(false),
had(false),
actualHad(false),
finished(false),
will(false),
mode(0) {}
@ -128,7 +129,7 @@ class DivMacroInt {
e(NULL),
ins(NULL),
macroListLen(0),
subTick(0),
subTick(1),
released(false),
vol(),
arp(),

View File

@ -1654,7 +1654,7 @@ bool DivEngine::nextTick(bool noAccum) {
}
}
if (consoleMode) fprintf(stderr,"\x1b[2K> %d:%.2d:%.2d.%.2d %.2x/%.2x:%.3d/%.3d %4dcmd/s\x1b[G",totalSeconds/3600,(totalSeconds/60)%60,totalSeconds%60,totalTicks/10000,curOrder,song.ordersLen,curRow,song.patLen,cmdsPerSecond);
if (consoleMode && subticks<=1) fprintf(stderr,"\x1b[2K> %d:%.2d:%.2d.%.2d %.2x/%.2x:%.3d/%.3d %4dcmd/s\x1b[G",totalSeconds/3600,(totalSeconds/60)%60,totalSeconds%60,totalTicks/10000,curOrder,song.ordersLen,curRow,song.patLen,cmdsPerSecond);
}
if (haltOn==DIV_HALT_TICK) halted=true;