diff --git a/src/engine/platform/sound/tia/Audio.cpp b/src/engine/platform/sound/tia/Audio.cpp index 662bd7fd5..3b38cc9c4 100644 --- a/src/engine/platform/sound/tia/Audio.cpp +++ b/src/engine/platform/sound/tia/Audio.cpp @@ -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: - myChannel0.phase0(); - myChannel1.phase0(); + myCounter-=len; + while (myCounter<=0) { + switch (myPhase) { + case 0: + case 2: + myChannel0.phase0(); + myChannel1.phase0(); + break; - break; - - case 37: - case 149: - phase1(); - break; + case 1: + case 3: + phase1(); + break; + } + if (++myPhase>4) myPhase=0; + myCounter+=phaseCounters[myPhase]; } - - if (++myCounter == 228) myCounter = 0; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/engine/platform/sound/tia/Audio.h b/src/engine/platform/sound/tia/Audio.h index 4a782bb38..97a7714cd 100644 --- a/src/engine/platform/sound/tia/Audio.h +++ b/src/engine/platform/sound/tia/Audio.h @@ -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; diff --git a/src/engine/platform/tia.cpp b/src/engine/platform/tia.cpp index 8f846f6bc..7fe977c48 100644 --- a/src/engine/platform/tia.cpp +++ b/src/engine/platform/tia.cpp @@ -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=228) { + if (456-tuneCounter>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; } diff --git a/src/engine/platform/tia.h b/src/engine/platform/tia.h index fa5af5c1b..fcb60a8f0 100644 --- a/src/engine/platform/tia.h +++ b/src/engine/platform/tia.h @@ -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);