Refactoring
This commit is contained in:
parent
f1c40082d6
commit
2423ec9bc6
|
@ -96,16 +96,16 @@ void DivPlatformPOKEY::acquireMZ(short* buf, size_t start, size_t len) {
|
|||
void DivPlatformPOKEY::acquireASAP(short* buf, size_t start, size_t len) {
|
||||
while (!writes.empty()) {
|
||||
QueuedWrite w=writes.front();
|
||||
altASAP->write(w.addr, w.val);
|
||||
altASAP.write(w.addr, w.val);
|
||||
writes.pop();
|
||||
}
|
||||
|
||||
for (size_t h=start; h<start+len; h++) {
|
||||
if (++oscBufDelay>=2) {
|
||||
oscBufDelay=0;
|
||||
buf[h]=altASAP->sampleAudio(oscBuf);
|
||||
buf[h]=altASAP.sampleAudio(oscBuf);
|
||||
} else {
|
||||
buf[h]=altASAP->sampleAudio();
|
||||
buf[h]=altASAP.sampleAudio();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ DivDispatchOscBuffer* DivPlatformPOKEY::getOscBuffer(int ch) {
|
|||
|
||||
unsigned char* DivPlatformPOKEY::getRegisterPool() {
|
||||
if (useAltASAP) {
|
||||
return const_cast<unsigned char*>(altASAP->getRegisterPool());
|
||||
return const_cast<unsigned char*>(altASAP.getRegisterPool());
|
||||
} else {
|
||||
return regPool;
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ void DivPlatformPOKEY::reset() {
|
|||
}
|
||||
|
||||
if (useAltASAP) {
|
||||
altASAP->reset();
|
||||
altASAP.reset();
|
||||
} else {
|
||||
ResetPokeyState(&pokey);
|
||||
}
|
||||
|
@ -454,11 +454,9 @@ void DivPlatformPOKEY::setFlags(const DivConfig& flags) {
|
|||
for (int i=0; i<4; i++) {
|
||||
oscBuf[i]->rate=rate/2;
|
||||
}
|
||||
if (altASAP) {
|
||||
delete altASAP;
|
||||
}
|
||||
altASAP=new AltASAP::Pokey(chipClock,rate);
|
||||
altASAP.init(chipClock,rate);
|
||||
} else {
|
||||
MZPOKEYSND_Init(&pokey);
|
||||
rate=chipClock;
|
||||
for (int i=0; i<4; i++) {
|
||||
oscBuf[i]->rate=rate/14;
|
||||
|
@ -479,16 +477,11 @@ int DivPlatformPOKEY::init(DivEngine* p, int channels, int sugRate, const DivCon
|
|||
dumpWrites=false;
|
||||
skipRegisterWrites=false;
|
||||
oscBufDelay=0;
|
||||
altASAP=NULL;
|
||||
for (int i=0; i<4; i++) {
|
||||
isMuted[i]=false;
|
||||
oscBuf[i]=new DivDispatchOscBuffer;
|
||||
}
|
||||
|
||||
if (!useAltASAP) {
|
||||
MZPOKEYSND_Init(&pokey);
|
||||
}
|
||||
|
||||
setFlags(flags);
|
||||
reset();
|
||||
return 6;
|
||||
|
@ -498,9 +491,6 @@ void DivPlatformPOKEY::quit() {
|
|||
for (int i=0; i<4; i++) {
|
||||
delete oscBuf[i];
|
||||
}
|
||||
if (altASAP) {
|
||||
delete altASAP;
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::setAltASAP(bool value) {
|
||||
|
|
|
@ -52,7 +52,7 @@ class DivPlatformPOKEY: public DivDispatch {
|
|||
bool audctlChanged;
|
||||
unsigned char oscBufDelay;
|
||||
PokeyState pokey;
|
||||
AltASAP::Pokey* altASAP;
|
||||
AltASAP::Pokey altASAP;
|
||||
bool useAltASAP;
|
||||
unsigned char regPool[16];
|
||||
friend void putDispatchChip(void*,int);
|
||||
|
|
|
@ -283,9 +283,8 @@ public:
|
|||
|
||||
PokeyPimpl( uint32_t pokeyClock, uint32_t sampleRate ) : PokeyBase{}, mQueue{ std::make_unique<ActionQueue>() },
|
||||
mAudioChannels{ AudioChannel{ *mQueue, 0u }, AudioChannel{ *mQueue, 1u }, AudioChannel{ *mQueue, 2u }, AudioChannel{ *mQueue, 3u } },
|
||||
mRegisterPool{}, mPokeyClock{ pokeyClock * 8 }, mTick{}, mNextTick{}, mSampleRate{ sampleRate }, mSamplesRemainder{},
|
||||
mReloadCycles1{ 28 }, mReloadCycles3{ 28 }, mDivCycles{ 28 },
|
||||
mTicksPerSample{ mPokeyClock / mSampleRate, mPokeyClock % mSampleRate }
|
||||
mRegisterPool{}, mTick{}, mNextTick{}, mReloadCycles1{ 28 }, mReloadCycles3{ 28 }, mDivCycles{ 28 }, mSampleRate{ sampleRate }, mSamplesRemainder{},
|
||||
mTicksPerSample{ ( pokeyClock * 8 ) / mSampleRate, ( pokeyClock * 8 ) % mSampleRate }
|
||||
{
|
||||
std::fill_n( mRegisterPool.data(), mRegisterPool.size(), (uint8_t)0xff );
|
||||
enqueueSampling();
|
||||
|
@ -468,7 +467,7 @@ public:
|
|||
for ( int i = 0; i < 4; i++ )
|
||||
mAudioChannels[i].doStimer( cycle );
|
||||
break;
|
||||
case 0x0f:
|
||||
case 0x0f:
|
||||
{
|
||||
if ( value == mSkctl )
|
||||
break;
|
||||
|
@ -600,45 +599,53 @@ private:
|
|||
|
||||
std::array<uint8_t, 4 * 2 + 1> mRegisterPool;
|
||||
|
||||
uint32_t mPokeyClock;
|
||||
uint64_t mTick;
|
||||
uint64_t mNextTick;
|
||||
int64_t mReloadCycles1;
|
||||
int64_t mReloadCycles3;
|
||||
int64_t mDivCycles;
|
||||
uint32_t mSampleRate;
|
||||
uint32_t mSamplesRemainder;
|
||||
int mReloadCycles1;
|
||||
int mReloadCycles3;
|
||||
int mDivCycles;
|
||||
std::pair<uint32_t, uint32_t> mTicksPerSample;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Pokey::Pokey( uint32_t pokeyClock, uint32_t sampleRate ) : mPokey{ std::make_unique<PokeyPimpl>( mPokeyClock, mSampleRate ) }, mPokeyClock{ pokeyClock }, mSampleRate{ sampleRate }
|
||||
//Initializing periods with safe defaults
|
||||
Pokey::Pokey() : mPokeyClock{ (uint32_t)COLOR_NTSC / 2 }, mSampleRate{ mPokeyClock / 7 }, mPokey{}
|
||||
{
|
||||
}
|
||||
|
||||
void Pokey::init( uint32_t pokeyClock, uint32_t sampleRate )
|
||||
{
|
||||
mPokey.reset();
|
||||
mPokeyClock = pokeyClock;
|
||||
mSampleRate = sampleRate;
|
||||
}
|
||||
|
||||
void Pokey::reset()
|
||||
{
|
||||
mPokey = std::make_unique<PokeyPimpl>( mPokeyClock, mSampleRate );
|
||||
}
|
||||
|
||||
Pokey::~Pokey()
|
||||
{
|
||||
}
|
||||
|
||||
void Pokey::write( uint8_t address, uint8_t value )
|
||||
{
|
||||
assert( mPokey );
|
||||
mPokey->write( address, value );
|
||||
}
|
||||
|
||||
int16_t Pokey::sampleAudio( DivDispatchOscBuffer** oscb )
|
||||
{
|
||||
assert( mPokey );
|
||||
return mPokey->sampleAudio( oscb );
|
||||
}
|
||||
|
||||
uint8_t const* Pokey::getRegisterPool()
|
||||
{
|
||||
assert( mPokey );
|
||||
return mPokey->getRegisterPool();
|
||||
}
|
||||
|
||||
void Pokey::reset()
|
||||
{
|
||||
mPokey = std::make_unique<PokeyPimpl>( mPokeyClock, mSampleRate );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ class Pokey
|
|||
{
|
||||
public:
|
||||
|
||||
Pokey( uint32_t pokeyClock, uint32_t sampleRate );
|
||||
Pokey();
|
||||
void init( uint32_t pokeyClock, uint32_t sampleRate );
|
||||
~Pokey();
|
||||
|
||||
void write( uint8_t address, uint8_t value );
|
||||
|
@ -26,10 +27,9 @@ public:
|
|||
void reset();
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<PokeyPimpl> mPokey;
|
||||
uint32_t mPokeyClock;
|
||||
uint32_t mSampleRate;
|
||||
std::unique_ptr<PokeyPimpl> mPokey;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue