Skip to content

Commit

Permalink
SBEMU: limit time constants and avoid divide by zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
crazii committed Jan 23, 2024
1 parent 90d83cf commit f6eb07c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sbemu/sbemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,18 @@ void SBEMU_DSP_Write(uint16_t port, uint8_t value)
}
}
if(SBEMU_SampleRate == 0)
{
uint8_t limit = 212; //23K Hz. limit time constant. reference: sblaster.cpp from DOSBox-X.
if(SBEMU_DSPVER >= 0x0400) //SB16
limit = SBEMU_GetBits() == 2 ? 165 : (SBEMU_GetBits() == 3 ? 179 : (SBEMU_GetBits() == 4 ? 172 : 234));
else if(SBEMU_DSPVER >= 0x0300) //SBPro
limit = SBEMU_GetBits() == 2 ? 165 : (SBEMU_GetBits() == 3 ? 179 : (SBEMU_GetBits() == 4 ? 172 : (SBEMU_HighSpeed?234:212)));
else //SB2.0
limit = SBEMU_GetBits() == 2 ? 189 : (SBEMU_GetBits() <= 4 ? 172 : ((SBEMU_HighSpeed?234:210)));
value = min(value, limit);

SBEMU_SampleRate = 256000000/(65536-(value<<8)) / SBEMU_GetChannels();
}
SBEMU_DSPCMD_Subindex = 2; //only 1byte
SBEMU_UseTimeConst = SBEMU_GetChannels(); // 1 or 2
//_LOG("SBEMU: set sampling rate: %d", SBEMU_SampleRate);
Expand Down

0 comments on commit f6eb07c

Please sign in to comment.