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 { namespace TIA {
static const int phaseCounters[5]={
9,
28,
44,
68,
79
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Audio::Audio() Audio::Audio()
{ {
@ -46,7 +54,8 @@ Audio::Audio()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Audio::reset(bool st) void Audio::reset(bool st)
{ {
myCounter = 0; myCounter = 9;
myPhase = 0;
mySampleIndex = 0; mySampleIndex = 0;
stereo = st; 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) { myCounter-=len;
case 9: while (myCounter<=0) {
case 81: switch (myPhase) {
case 0:
case 2:
myChannel0.phase0(); myChannel0.phase0();
myChannel1.phase0(); myChannel1.phase0();
break; break;
case 37: case 1:
case 149: case 3:
phase1(); phase1();
break; break;
} }
if (++myPhase>4) myPhase=0;
if (++myCounter == 228) myCounter = 0; myCounter+=phaseCounters[myPhase];
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View file

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

View file

@ -38,15 +38,32 @@ const char** DivPlatformTIA::getRegisterSheet() {
return regCheatSheetTIA; 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++) { for (int i=0; i<2; i++) {
oscBuf[i]->begin(len); oscBuf[i]->begin(len);
} }
for (size_t h=0; h<len; h++) { 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) { if (softwarePitch) {
int i=-1; int i=-1;
tuneCounter++; tuneCounter+=advance;
if (tuneCounter==228) { if (tuneCounter==228) {
i=0; 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) { if (mixingType==2) {
buf[0][h]=tia.myCurrentSample[0]; out[0]=tia.myCurrentSample[0];
buf[1][h]=tia.myCurrentSample[1]; out[1]=tia.myCurrentSample[1];
} else if (mixingType==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 { } 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) { if (++chanOscCounter>=114) {
chanOscCounter=0; chanOscCounter=0;
@ -428,6 +457,8 @@ int DivPlatformTIA::getRegisterPoolSize() {
void DivPlatformTIA::reset() { void DivPlatformTIA::reset() {
tuneCounter=0; tuneCounter=0;
prevSample[0]=0;
prevSample[1]=0;
tia.reset(mixingType); tia.reset(mixingType);
memset(regPool,0,16); memset(regPool,0,16);
for (int i=0; i<2; i++) { for (int i=0; i<2; i++) {
@ -449,6 +480,10 @@ bool DivPlatformTIA::keyOffAffectsArp(int ch) {
return true; return true;
} }
bool DivPlatformTIA::hasAcquireDirect() {
return true;
}
bool DivPlatformTIA::getLegacyAlwaysSetVolume() { bool DivPlatformTIA::getLegacyAlwaysSetVolume() {
return false; return false;
} }

View file

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