some time refactors
no more weird totalTicks name code looks better
This commit is contained in:
parent
a2b56b5b64
commit
5ff81aef33
16 changed files with 256 additions and 211 deletions
|
|
@ -1511,8 +1511,7 @@ String DivEngine::getPlaybackDebugInfo() {
|
|||
"midiTimeDrift: %f\n"
|
||||
"changeOrd: %d\n"
|
||||
"changePos: %d\n"
|
||||
"totalSeconds: %d\n"
|
||||
"totalTicks: %d\n"
|
||||
"totalTime: %s\n"
|
||||
"totalTicksR: %d\n"
|
||||
"curMidiClock: %d\n"
|
||||
"curMidiTime: %d\n"
|
||||
|
|
@ -1524,7 +1523,7 @@ String DivEngine::getPlaybackDebugInfo() {
|
|||
"totalProcessed: %d\n"
|
||||
"bufferPos: %d\n",
|
||||
curOrder,prevOrder,curRow,prevRow,ticks,subticks,totalLoops,lastLoopPos,nextSpeed,divider,cycles,clockDrift,
|
||||
midiClockCycles,midiClockDrift,midiTimeCycles,midiTimeDrift,changeOrd,changePos,totalSeconds,totalTicks,
|
||||
midiClockCycles,midiClockDrift,midiTimeCycles,midiTimeDrift,changeOrd,changePos,totalTime.toString(),
|
||||
totalTicksR,curMidiClock,curMidiTime,totalCmds,lastCmds,cmdsPerSecond,
|
||||
(int)extValue,(int)tempoAccum,(int)totalProcessed,(int)bufferPos
|
||||
);
|
||||
|
|
@ -1662,27 +1661,17 @@ void DivEngine::setFilePlayerSync(bool doSync) {
|
|||
filePlayerSync=doSync;
|
||||
}
|
||||
|
||||
void DivEngine::getFilePlayerCue(int& seconds, int& micros) {
|
||||
seconds=filePlayerCueSeconds;
|
||||
micros=filePlayerCueMicros;
|
||||
TimeMicros DivEngine::getFilePlayerCue() {
|
||||
return filePlayerCue;
|
||||
}
|
||||
|
||||
void DivEngine::setFilePlayerCue(int seconds, int micros) {
|
||||
filePlayerCueSeconds=seconds;
|
||||
filePlayerCueMicros=micros;
|
||||
void DivEngine::setFilePlayerCue(TimeMicros cue) {
|
||||
filePlayerCue=cue;
|
||||
}
|
||||
|
||||
void DivEngine::syncFilePlayer() {
|
||||
if (curFilePlayer==NULL) return;
|
||||
int finalSeconds=totalSeconds+filePlayerCueSeconds;
|
||||
int finalMicros=totalTicks+filePlayerCueMicros;
|
||||
|
||||
while (finalMicros>=1000000) {
|
||||
finalMicros-=1000000;
|
||||
finalSeconds++;
|
||||
}
|
||||
|
||||
curFilePlayer->setPosSeconds(finalSeconds,finalMicros);
|
||||
curFilePlayer->setPosSeconds(totalTime+filePlayerCue);
|
||||
}
|
||||
|
||||
void DivEngine::playSub(bool preserveDrift, int goalRow) {
|
||||
|
|
@ -1717,9 +1706,8 @@ void DivEngine::playSub(bool preserveDrift, int goalRow) {
|
|||
ticks=1;
|
||||
subticks=0;
|
||||
tempoAccum=0;
|
||||
totalTicks=0;
|
||||
totalTime=TimeMicros(0,0);
|
||||
totalTicksOff=0;
|
||||
totalSeconds=0;
|
||||
totalTicksR=0;
|
||||
curMidiClock=0;
|
||||
curMidiTime=0;
|
||||
|
|
@ -1809,7 +1797,7 @@ void DivEngine::playSub(bool preserveDrift, int goalRow) {
|
|||
cmdStream.clear();
|
||||
std::chrono::high_resolution_clock::time_point timeEnd=std::chrono::high_resolution_clock::now();
|
||||
logV("playSub() took %dµs",std::chrono::duration_cast<std::chrono::microseconds>(timeEnd-timeStart).count());
|
||||
logV("and landed us at %d.%06d (%d ticks, %d:%d.%d)",totalSeconds,totalTicks,totalTicksR,curOrder,curRow,ticks);
|
||||
logV("and landed us at %s (%d ticks, %d:%d.%d)",totalTime.toString(),totalTicksR,curOrder,curRow,ticks);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -2569,12 +2557,8 @@ void DivEngine::virtualTempoChanged() {
|
|||
BUSY_END;
|
||||
}
|
||||
|
||||
int DivEngine::getTotalSeconds() {
|
||||
return totalSeconds;
|
||||
}
|
||||
|
||||
int DivEngine::getTotalTicks() {
|
||||
return totalTicks;
|
||||
TimeMicros DivEngine::getCurTime() {
|
||||
return totalTime;
|
||||
}
|
||||
|
||||
bool DivEngine::getRepeatPattern() {
|
||||
|
|
@ -3995,9 +3979,8 @@ void DivEngine::quitDispatch() {
|
|||
nextSpeed=3;
|
||||
changeOrd=-1;
|
||||
changePos=0;
|
||||
totalTicks=0;
|
||||
totalTime=TimeMicros(0,0);
|
||||
totalTicksOff=0;
|
||||
totalSeconds=0;
|
||||
totalTicksR=0;
|
||||
curMidiClock=0;
|
||||
curMidiTime=0;
|
||||
|
|
|
|||
|
|
@ -510,7 +510,8 @@ class DivEngine {
|
|||
int midiTimeCycles;
|
||||
double midiTimeDrift;
|
||||
int stepPlay;
|
||||
int changeOrd, changePos, totalSeconds, totalTicks, totalTicksR, curMidiClock, curMidiTime, totalCmds, lastCmds, cmdsPerSecond;
|
||||
int changeOrd, changePos, totalTicksR, curMidiClock, curMidiTime, totalCmds, lastCmds, cmdsPerSecond;
|
||||
TimeMicros totalTime;
|
||||
double totalTicksOff;
|
||||
int curMidiTimePiece, curMidiTimeCode;
|
||||
unsigned char extValue, pendingMetroTick;
|
||||
|
|
@ -602,8 +603,7 @@ class DivEngine {
|
|||
size_t filePlayerBufLen;
|
||||
DivFilePlayer* curFilePlayer;
|
||||
bool filePlayerSync;
|
||||
ssize_t filePlayerCueSeconds;
|
||||
unsigned int filePlayerCueMicros;
|
||||
TimeMicros filePlayerCue;
|
||||
int filePlayerLoopTrail;
|
||||
int curFilePlayerTrail;
|
||||
|
||||
|
|
@ -763,8 +763,8 @@ class DivEngine {
|
|||
bool getFilePlayerSync();
|
||||
void setFilePlayerSync(bool doSync);
|
||||
// get/set file player cue position.
|
||||
void getFilePlayerCue(int& seconds, int& micros);
|
||||
void setFilePlayerCue(int seconds, int micros);
|
||||
TimeMicros getFilePlayerCue();
|
||||
void setFilePlayerCue(TimeMicros cue);
|
||||
// UNSAFE - sync file player to current playback position.
|
||||
void syncFilePlayer();
|
||||
|
||||
|
|
@ -1049,8 +1049,7 @@ class DivEngine {
|
|||
void virtualTempoChanged();
|
||||
|
||||
// get time
|
||||
int getTotalTicks(); // 1/1000000th of a second
|
||||
int getTotalSeconds();
|
||||
TimeMicros getCurTime();
|
||||
|
||||
// get repeat pattern
|
||||
bool getRepeatPattern();
|
||||
|
|
@ -1525,8 +1524,6 @@ class DivEngine {
|
|||
stepPlay(0),
|
||||
changeOrd(-1),
|
||||
changePos(0),
|
||||
totalSeconds(0),
|
||||
totalTicks(0),
|
||||
totalTicksR(0),
|
||||
curMidiClock(0),
|
||||
curMidiTime(0),
|
||||
|
|
@ -1576,8 +1573,7 @@ class DivEngine {
|
|||
filePlayerBufLen(0),
|
||||
curFilePlayer(NULL),
|
||||
filePlayerSync(false),
|
||||
filePlayerCueSeconds(0),
|
||||
filePlayerCueMicros(0),
|
||||
filePlayerCue(0,0),
|
||||
filePlayerLoopTrail(0),
|
||||
curFilePlayerTrail(0),
|
||||
totalProcessed(0),
|
||||
|
|
|
|||
|
|
@ -298,15 +298,15 @@ ssize_t DivFilePlayer::getPos() {
|
|||
return playPos;
|
||||
}
|
||||
|
||||
void DivFilePlayer::getPosSeconds(ssize_t& seconds, unsigned int& micros) {
|
||||
TimeMicros DivFilePlayer::getPosSeconds() {
|
||||
if (sf==NULL) {
|
||||
seconds=0;
|
||||
micros=0;
|
||||
return;
|
||||
return TimeMicros(0,0);
|
||||
}
|
||||
double microsD=playPos%si.samplerate;
|
||||
seconds=playPos/si.samplerate;
|
||||
micros=(int)((1000000.0*microsD)/(double)si.samplerate);
|
||||
return TimeMicros(
|
||||
playPos/si.samplerate, // seconds
|
||||
(int)((1000000.0*microsD)/(double)si.samplerate) // microseconds
|
||||
);
|
||||
}
|
||||
|
||||
ssize_t DivFilePlayer::setPos(ssize_t newPos, unsigned int offset) {
|
||||
|
|
@ -325,20 +325,20 @@ ssize_t DivFilePlayer::setPos(ssize_t newPos, unsigned int offset) {
|
|||
}
|
||||
}
|
||||
|
||||
ssize_t DivFilePlayer::setPosSeconds(ssize_t seconds, unsigned int micros, unsigned int offset) {
|
||||
ssize_t DivFilePlayer::setPosSeconds(TimeMicros newTime, unsigned int offset) {
|
||||
if (sf==NULL) return 0;
|
||||
double microsD=(double)si.samplerate*((double)micros/1000000.0);
|
||||
double microsD=(double)si.samplerate*((double)newTime.micros/1000000.0);
|
||||
if (offset==UINT_MAX) {
|
||||
playPos=seconds*si.samplerate+(int)microsD;
|
||||
playPos=(ssize_t)newTime.seconds*(ssize_t)si.samplerate+(int)microsD;
|
||||
rateAccum=0;
|
||||
wantBlock=playPos;
|
||||
logD("DivFilePlayer: setPosSeconds(%" PRIi64 ".%06d)",seconds,micros);
|
||||
logD("DivFilePlayer: setPosSeconds(%s)",newTime.toString());
|
||||
return playPos;
|
||||
} else {
|
||||
pendingPosOffset=offset;
|
||||
pendingPos=seconds*si.samplerate+(int)microsD;
|
||||
pendingPos=(ssize_t)newTime.seconds*(ssize_t)si.samplerate+(int)microsD;
|
||||
wantBlock=pendingPos;
|
||||
logD("DivFilePlayer: offset %u setPosSeconds(%" PRIi64 ".%06d)",offset,seconds,micros);
|
||||
logD("DivFilePlayer: offset %u setPosSeconds(%s)",offset,newTime.toString());
|
||||
return pendingPos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define _FILEPLAYER_H
|
||||
|
||||
#include "../ta-utils.h"
|
||||
#include "../timeutils.h"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
|
@ -78,9 +79,9 @@ class DivFilePlayer {
|
|||
|
||||
void mix(float** buf, int chans, unsigned int size);
|
||||
ssize_t getPos();
|
||||
void getPosSeconds(ssize_t& seconds, unsigned int& micros);
|
||||
TimeMicros getPosSeconds();
|
||||
ssize_t setPos(ssize_t newPos, unsigned int offset=UINT_MAX);
|
||||
ssize_t setPosSeconds(ssize_t seconds, unsigned int micros, unsigned int offset=UINT_MAX);
|
||||
ssize_t setPosSeconds(TimeMicros newTime, unsigned int offset=UINT_MAX);
|
||||
|
||||
bool isBlockPresent(ssize_t pos);
|
||||
bool setBlockPriority(ssize_t pos, bool priority);
|
||||
|
|
|
|||
|
|
@ -2172,8 +2172,9 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
|
|||
|
||||
// also set the playback position and sync file player if necessary
|
||||
TimeMicros rowTS=curSubSong->ts.getTimes(curOrder,curRow);
|
||||
totalSeconds=rowTS.seconds;
|
||||
totalTicks=rowTS.micros;
|
||||
if (rowTS.seconds!=-1) {
|
||||
totalTime=rowTS;
|
||||
}
|
||||
if (curFilePlayer && filePlayerSync) {
|
||||
syncFilePlayer();
|
||||
}
|
||||
|
|
@ -2581,25 +2582,27 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
|
|||
if (!noAccum) {
|
||||
double dt=divider*tickMult;
|
||||
totalTicksR++;
|
||||
// despite the name, totalTicks is in microseconds...
|
||||
totalTicks+=1000000/dt;
|
||||
totalTime.micros+=1000000/dt;
|
||||
totalTicksOff+=fmod(1000000.0,dt);
|
||||
while (totalTicksOff>=dt) {
|
||||
totalTicksOff-=dt;
|
||||
totalTicks++;
|
||||
totalTime.micros++;
|
||||
}
|
||||
}
|
||||
if (totalTicks>=1000000) {
|
||||
totalTicks-=1000000;
|
||||
if (totalTime.micros>=1000000) {
|
||||
totalTime.micros-=1000000;
|
||||
// who's gonna play a song for 68 years?
|
||||
if (totalSeconds<0x7fffffff) totalSeconds++;
|
||||
if (totalTime.seconds<0x7fffffff) totalTime.seconds++;
|
||||
cmdsPerSecond=totalCmds-lastCmds;
|
||||
lastCmds=totalCmds;
|
||||
}
|
||||
}
|
||||
|
||||
// print status in console mode
|
||||
if (consoleMode && !disableStatusOut && subticks<=1 && !skipping) 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,curSubSong->ordersLen,curRow,curSubSong->patLen,cmdsPerSecond);
|
||||
if (consoleMode && !disableStatusOut && subticks<=1 && !skipping) {
|
||||
String timeFormatted=totalTime.toString(2,TA_TIME_FORMAT_HMS);
|
||||
fprintf(stderr,"\x1b[2K> %s %.2x/%.2x:%.3d/%.3d %4dcmd/s\x1b[G",timeFormatted.c_str(),curOrder,curSubSong->ordersLen,curRow,curSubSong->patLen,cmdsPerSecond);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -3110,15 +3113,12 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
if (curFilePlayer && filePlayerSync) {
|
||||
if (curFilePlayer->isPlaying()) {
|
||||
TimeMicros rowTS=curSubSong->ts.loopStartTime;
|
||||
int finalSeconds=rowTS.seconds+filePlayerCueSeconds;
|
||||
int finalMicros=rowTS.micros+filePlayerCueMicros;
|
||||
|
||||
while (finalMicros>=1000000) {
|
||||
finalMicros-=1000000;
|
||||
finalSeconds++;
|
||||
if (rowTS.seconds==-1) {
|
||||
logW("that row isn't supposed to play. report this now!");
|
||||
}
|
||||
|
||||
curFilePlayer->setPosSeconds(finalSeconds,finalMicros,lastLoopPos);
|
||||
curFilePlayer->setPosSeconds(rowTS+filePlayerCue,lastLoopPos);
|
||||
}
|
||||
}
|
||||
// increase total loop count
|
||||
|
|
@ -3232,7 +3232,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
// complain and stop playback if we believe the engine has stalled
|
||||
//logD("attempts: %d",attempts);
|
||||
if (attempts>=(int)(size+10)) {
|
||||
logE("hang detected! stopping! at %d seconds %d micro (%d>=%d)",totalSeconds,totalTicks,attempts,(int)size);
|
||||
logE("hang detected! stopping! at %s (%d>=%d)",totalTime.toString(),attempts,(int)size);
|
||||
freelance=false;
|
||||
playing=false;
|
||||
extValuePresent=false;
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ TimeMicros DivSongTimestamps::getTimes(int order, int row) {
|
|||
}
|
||||
|
||||
DivSongTimestamps::DivSongTimestamps():
|
||||
totalSeconds(0),
|
||||
totalMicros(0),
|
||||
totalTime(0,0),
|
||||
totalTicks(0),
|
||||
totalRows(0),
|
||||
isLoopDefined(false),
|
||||
|
|
@ -54,8 +53,7 @@ void DivSubSong::calcTimestamps(int chans, std::vector<DivGroovePattern>& groove
|
|||
std::chrono::high_resolution_clock::time_point timeStart=std::chrono::high_resolution_clock::now();
|
||||
|
||||
// reset state
|
||||
ts.totalSeconds=0;
|
||||
ts.totalMicros=0;
|
||||
ts.totalTime=TimeMicros(0,0);
|
||||
ts.totalTicks=0;
|
||||
ts.totalRows=0;
|
||||
ts.isLoopDefined=true;
|
||||
|
|
@ -396,7 +394,7 @@ void DivSubSong::calcTimestamps(int chans, std::vector<DivGroovePattern>& groove
|
|||
ts.orders[prevOrder][i].seconds=-1;
|
||||
}
|
||||
}
|
||||
ts.orders[prevOrder][prevRow]=TimeMicros(ts.totalSeconds,ts.totalMicros);
|
||||
ts.orders[prevOrder][prevRow]=ts.totalTime;
|
||||
rowChanged=false;
|
||||
}
|
||||
|
||||
|
|
@ -405,16 +403,16 @@ void DivSubSong::calcTimestamps(int chans, std::vector<DivGroovePattern>& groove
|
|||
double dt=divider;//*((double)virtualTempoN/(double)MAX(1,virtualTempoD));
|
||||
ts.totalTicks++;
|
||||
|
||||
ts.totalMicros+=1000000/dt;
|
||||
ts.totalTime.micros+=1000000/dt;
|
||||
totalMicrosOff+=fmod(1000000.0,dt);
|
||||
while (totalMicrosOff>=dt) {
|
||||
totalMicrosOff-=dt;
|
||||
ts.totalMicros++;
|
||||
ts.totalTime.micros++;
|
||||
}
|
||||
if (ts.totalMicros>=1000000) {
|
||||
ts.totalMicros-=1000000;
|
||||
if (ts.totalTime.micros>=1000000) {
|
||||
ts.totalTime.micros-=1000000;
|
||||
// who's gonna play a song for 68 years?
|
||||
if (ts.totalSeconds<0x7fffffff) ts.totalSeconds++;
|
||||
if (ts.totalTime.seconds<0x7fffffff) ts.totalTime.seconds++;
|
||||
}
|
||||
}
|
||||
if (ts.maxRow[curOrder]<curRow) ts.maxRow[curOrder]=curRow;
|
||||
|
|
|
|||
|
|
@ -170,8 +170,7 @@ struct DivGroovePattern {
|
|||
|
||||
struct DivSongTimestamps {
|
||||
// song duration (in seconds and microseconds)
|
||||
int totalSeconds;
|
||||
int totalMicros;
|
||||
TimeMicros totalTime;
|
||||
int totalTicks;
|
||||
int totalRows;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue