TIA: acquireDirect()

# TIA Benchmark

twin.fur

acquire(): 11.324s
acquireDirect(): 1.267s

Balmeranda.fur

acquire(): 11.923s
acquireDirect(): 1.093s

# MMC5 (Goofy Asses per second)

unoptimized: 9.22/s
optimized: 108.96/s
This commit is contained in:
tildearrow 2025-03-07 03:58:13 -05:00
parent 9730988cef
commit 8ee01d15f7
4 changed files with 83 additions and 26 deletions

View file

@ -34,6 +34,14 @@ namespace {
namespace TIA {
static const int phaseCounters[5]={
9,
28,
44,
68,
79
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Audio::Audio()
{
@ -46,7 +54,8 @@ Audio::Audio()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Audio::reset(bool st)
{
myCounter = 0;
myCounter = 9;
myPhase = 0;
mySampleIndex = 0;
stereo = st;
@ -61,23 +70,32 @@ void Audio::reset(bool st)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Audio::tick()
// steps: (228 total)
// 0 - wait
// 1 - 9: phase0
// 2 - 37: phase1
// 3 - 81: phase0
// 4 - 149: phase1
// 5 - 228: go back to step 0
void Audio::tick(int len)
{
switch (myCounter) {
case 9:
case 81:
myCounter-=len;
while (myCounter<=0) {
switch (myPhase) {
case 0:
case 2:
myChannel0.phase0();
myChannel1.phase0();
break;
case 37:
case 149:
case 1:
case 3:
phase1();
break;
}
if (++myCounter == 228) myCounter = 0;
if (++myPhase>4) myPhase=0;
myCounter+=phaseCounters[myPhase];
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View file

@ -29,7 +29,7 @@ namespace TIA {
void reset(bool stereo);
void tick();
void tick(int len);
void write(unsigned char addr, unsigned char val);
@ -44,9 +44,11 @@ namespace TIA {
void phase1();
void addSample(unsigned char sample0, unsigned char sample1);
private:
unsigned char myCounter{0};
public:
int myCounter;
unsigned char myPhase;
private:
AudioChannel myChannel0;
AudioChannel myChannel1;

View file

@ -38,15 +38,32 @@ const char** DivPlatformTIA::getRegisterSheet() {
return regCheatSheetTIA;
}
void DivPlatformTIA::acquire(short** buf, size_t len) {
void DivPlatformTIA::acquireDirect(blip_buffer_t** bb, size_t len) {
thread_local int out[2];
for (int i=0; i<2; i++) {
oscBuf[i]->begin(len);
}
for (size_t h=0; h<len; h++) {
int advance=len-h;
if (tia.myCounter<advance) advance=tia.myCounter;
if (softwarePitch) {
if (tuneCounter>=228) {
if (456-tuneCounter<advance) {
advance=456-tuneCounter;
}
} else {
if (228-tuneCounter<advance) {
advance=228-tuneCounter;
}
}
}
if (advance<1) advance=1;
if (softwarePitch) {
int i=-1;
tuneCounter++;
tuneCounter+=advance;
if (tuneCounter==228) {
i=0;
}
@ -68,14 +85,26 @@ void DivPlatformTIA::acquire(short** buf, size_t len) {
}
}
}
tia.tick();
tia.tick(advance);
h+=advance-1;
if (mixingType==2) {
buf[0][h]=tia.myCurrentSample[0];
buf[1][h]=tia.myCurrentSample[1];
out[0]=tia.myCurrentSample[0];
out[1]=tia.myCurrentSample[1];
} else if (mixingType==1) {
buf[0][h]=(tia.myCurrentSample[0]+tia.myCurrentSample[1])>>1;
out[0]=(tia.myCurrentSample[0]+tia.myCurrentSample[1])>>1;
} else {
buf[0][h]=tia.myCurrentSample[0];
out[0]=tia.myCurrentSample[0];
}
if (out[0]!=prevSample[0]) {
blip_add_delta(bb[0],h,out[0]-prevSample[0]);
prevSample[0]=out[0];
}
if (mixingType==2) {
blip_add_delta(bb[1],h,out[1]-prevSample[1]);
prevSample[1]=out[1];
}
if (++chanOscCounter>=114) {
chanOscCounter=0;
@ -428,6 +457,8 @@ int DivPlatformTIA::getRegisterPoolSize() {
void DivPlatformTIA::reset() {
tuneCounter=0;
prevSample[0]=0;
prevSample[1]=0;
tia.reset(mixingType);
memset(regPool,0,16);
for (int i=0; i<2; i++) {
@ -449,6 +480,10 @@ bool DivPlatformTIA::keyOffAffectsArp(int ch) {
return true;
}
bool DivPlatformTIA::hasAcquireDirect() {
return true;
}
bool DivPlatformTIA::getLegacyAlwaysSetVolume() {
return false;
}

View file

@ -47,6 +47,7 @@ class DivPlatformTIA: public DivDispatch {
TIA::Audio tia;
unsigned char regPool[16];
int tuneCounter;
int prevSample[2];
friend void putDispatchChip(void*,int);
friend void putDispatchChan(void*,int,int);
@ -54,7 +55,7 @@ class DivPlatformTIA: public DivDispatch {
int dealWithFreqNew(int shape, int bp);
public:
void acquire(short** buf, size_t len);
void acquireDirect(blip_buffer_t** bb, size_t len);
int dispatch(DivCommand c);
void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch);
@ -69,6 +70,7 @@ class DivPlatformTIA: public DivDispatch {
float getPostAmp();
int getOutputCount();
bool keyOffAffectsArp(int ch);
bool hasAcquireDirect();
bool getLegacyAlwaysSetVolume();
void notifyInsDeletion(void* ins);
void poke(unsigned int addr, unsigned short val);