add clock drift for exact tempo
This commit is contained in:
parent
db2bfb8aa3
commit
9362cfa481
|
@ -836,7 +836,11 @@ bool DivEngine::init(String outName) {
|
|||
}
|
||||
}
|
||||
|
||||
sf_writef_short(outFile,ilBuffer,got.bufsize);
|
||||
if (!remainingLoops) {
|
||||
sf_writef_short(outFile,ilBuffer,totalProcessed);
|
||||
} else {
|
||||
sf_writef_short(outFile,ilBuffer,got.bufsize);
|
||||
}
|
||||
}
|
||||
delete[] ilBuffer;
|
||||
sf_close(outFile);
|
||||
|
|
|
@ -66,7 +66,7 @@ class DivEngine {
|
|||
bool playing;
|
||||
bool speedAB;
|
||||
bool endOfSong;
|
||||
int ticks, cycles, curRow, curOrder, remainingLoops, nextSpeed;
|
||||
int ticks, cycles, curRow, curOrder, remainingLoops, nextSpeed, clockDrift;
|
||||
int changeOrd, changePos, totalTicks, totalCmds, lastCmds, cmdsPerSecond;
|
||||
DivStatusView view;
|
||||
DivChannelState chan[17];
|
||||
|
@ -80,6 +80,8 @@ class DivEngine {
|
|||
short* bbIn[2];
|
||||
short* bbOut[2];
|
||||
|
||||
size_t totalProcessed;
|
||||
|
||||
int dispatchCmd(DivCommand c);
|
||||
void processRow(int i, bool afterDelay);
|
||||
void nextOrder();
|
||||
|
@ -126,6 +128,7 @@ class DivEngine {
|
|||
curOrder(0),
|
||||
remainingLoops(-1),
|
||||
nextSpeed(3),
|
||||
clockDrift(0),
|
||||
changeOrd(-1),
|
||||
changePos(0),
|
||||
totalTicks(0),
|
||||
|
|
|
@ -1180,11 +1180,11 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
|
|||
if ((value & 0x80)) {
|
||||
/* DMG bug: wave RAM gets corrupted if the channel is retriggerred 1 cycle before the APU
|
||||
reads from it. */
|
||||
if (!CGB &&
|
||||
/*if (!CGB &&
|
||||
gb->apu.is_active[GB_WAVE] &&
|
||||
gb->apu.wave_channel.sample_countdown == 0 &&
|
||||
gb->apu.wave_channel.enable) {
|
||||
unsigned offset = ((gb->apu.wave_channel.current_sample_index + 1) >> 1) & 0xF;
|
||||
unsigned offset = ((gb->apu.wave_channel.current_sample_index + 1) >> 1) & 0xF;*/
|
||||
|
||||
/* This glitch varies between models and even specific instances:
|
||||
DMG-B: Most of them behave as emulated. A few behave differently.
|
||||
|
@ -1193,7 +1193,7 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
|
|||
|
||||
Additionally, I believe DMGs, including those we behave differently than emulated,
|
||||
are all deterministic. */
|
||||
if (offset < 4) {
|
||||
/*if (offset < 4) {
|
||||
gb->io_registers[GB_IO_WAV_START] = gb->io_registers[GB_IO_WAV_START + offset];
|
||||
gb->apu.wave_channel.wave_form[0] = gb->apu.wave_channel.wave_form[offset / 2];
|
||||
gb->apu.wave_channel.wave_form[1] = gb->apu.wave_channel.wave_form[offset / 2 + 1];
|
||||
|
@ -1206,7 +1206,7 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
|
|||
gb->apu.wave_channel.wave_form + (offset & ~3) * 2,
|
||||
8);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (!gb->apu.is_active[GB_WAVE]) {
|
||||
gb->apu.is_active[GB_WAVE] = true;
|
||||
update_sample(gb, GB_WAVE,
|
||||
|
|
|
@ -569,15 +569,23 @@ void DivEngine::nextRow() {
|
|||
|
||||
bool DivEngine::nextTick() {
|
||||
bool ret=false;
|
||||
int divider=60;
|
||||
if (song.customTempo) {
|
||||
cycles=dispatch->rate/song.hz;
|
||||
divider=song.hz;
|
||||
} else {
|
||||
if (song.pal) {
|
||||
cycles=dispatch->rate/60;
|
||||
divider=60;
|
||||
} else {
|
||||
cycles=dispatch->rate/50;
|
||||
divider=50;
|
||||
}
|
||||
}
|
||||
cycles=dispatch->rate/divider;
|
||||
clockDrift+=dispatch->rate%divider;
|
||||
if (clockDrift>=divider) {
|
||||
clockDrift-=divider;
|
||||
cycles++;
|
||||
}
|
||||
|
||||
if (--ticks<=0) {
|
||||
ret=endOfSong;
|
||||
nextRow();
|
||||
|
@ -691,6 +699,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
|
||||
size_t runLeft=runtotal;
|
||||
size_t runPos=0;
|
||||
totalProcessed=0;
|
||||
while (runLeft) {
|
||||
if (!remainingLoops) {
|
||||
memset(bbIn[0]+runPos,0,runLeft*sizeof(short));
|
||||
|
@ -710,10 +719,12 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
} else {
|
||||
dispatch->acquire(bbIn[0],bbIn[1],runPos,runLeft);
|
||||
cycles-=runLeft;
|
||||
runPos=runtotal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
totalProcessed=(1+runPos)*got.rate/dispatch->rate;
|
||||
|
||||
for (size_t i=0; i<runtotal; i++) {
|
||||
temp[0]=bbIn[0][i];
|
||||
|
|
Loading…
Reference in a new issue