MinMod: fix spikes

This commit is contained in:
Natt Akuma 2024-03-19 14:22:16 +07:00 committed by tildearrow
parent 3d87a4284e
commit c698f72e97
2 changed files with 9 additions and 7 deletions

View file

@ -44,9 +44,8 @@ const char** DivPlatformGBAMinMod::getRegisterSheet() {
} }
void DivPlatformGBAMinMod::acquire(short** buf, size_t len) { void DivPlatformGBAMinMod::acquire(short** buf, size_t len) {
short sampL, sampR;
size_t sampPos=mixBufReadPos&3; size_t sampPos=mixBufReadPos&3;
bool newSamp=true; bool newSamp=false;
// cache channel registers that might change // cache channel registers that might change
struct { struct {
uint64_t address; uint64_t address;
@ -149,15 +148,15 @@ void DivPlatformGBAMinMod::acquire(short** buf, size_t len) {
memset(mixBuf[mixBufPage+1],0,sizeof(mixBuf[mixBufPage+1])); memset(mixBuf[mixBufPage+1],0,sizeof(mixBuf[mixBufPage+1]));
// emulate buffer loss prevention and buffer copying // emulate buffer loss prevention and buffer copying
sampsRendered+=mixBufReadPos; sampsRendered+=mixBufReadPos;
mixBufOffset=(4-(mixBufReadPos&3))&3; mixBufOffset=mixBufWritePos-mixBufReadPos;
mixBufReadPos=0;
mixBufWritePos=mixBufOffset;
for (size_t j=0; j<mixBufOffset; j++) { for (size_t j=0; j<mixBufOffset; j++) {
mixOut[0][j]=mixOut[0][4-mixBufOffset+j]; mixOut[0][j]=mixOut[0][(mixBufReadPos&3)+j];
mixOut[1][j]=mixOut[1][4-mixBufOffset+j]; mixOut[1][j]=mixOut[1][(mixBufReadPos&3)+j];
mixBuf[mixBufPage][j]=mixOut[0][j]; mixBuf[mixBufPage][j]=mixOut[0][j];
mixBuf[mixBufPage+1][j]=mixOut[1][j]; mixBuf[mixBufPage+1][j]=mixOut[1][j];
} }
mixBufReadPos=0;
mixBufWritePos=mixBufOffset;
// check for echo channels and give them proper addresses // check for echo channels and give them proper addresses
for (int i=0; i<chanMax; i++) { for (int i=0; i<chanMax; i++) {
unsigned char echoDelay=MIN(chan[i].echo&0x0f,mixBufs-1); unsigned char echoDelay=MIN(chan[i].echo&0x0f,mixBufs-1);
@ -602,6 +601,8 @@ void DivPlatformGBAMinMod::resetMixer() {
mixBufPage=0; mixBufPage=0;
mixBufOffset=0; mixBufOffset=0;
sampsRendered=0; sampsRendered=0;
sampL=0;
sampR=0;
memset(mixBuf,0,sizeof(mixBuf)); memset(mixBuf,0,sizeof(mixBuf));
memset(chanOut,0,sizeof(chanOut)); memset(chanOut,0,sizeof(chanOut));
} }

View file

@ -76,6 +76,7 @@ class DivPlatformGBAMinMod: public DivDispatch {
size_t mixBufReadPos; size_t mixBufReadPos;
size_t mixBufWritePos; size_t mixBufWritePos;
size_t mixBufOffset; size_t mixBufOffset;
short sampL, sampR;
signed char* sampleMem; signed char* sampleMem;
size_t sampleMemLen; size_t sampleMemLen;