mirror of
https://github.com/libretro/FBNeo.git
synced 2024-11-23 08:59:39 +00:00
stream.h, replace hacky rate change with proper fix
This commit is contained in:
parent
94dc5c01c4
commit
06b24bbe17
@ -957,7 +957,7 @@ static UINT8 __fastcall berzerk_read_port(UINT16 address)
|
||||
|
||||
switch (address & 0xff)
|
||||
{
|
||||
case 0x44: bprintf(0, _T("is busy? %x\n"), s14001a_busy_read());
|
||||
case 0x44:
|
||||
return (s14001a_busy_read()) ? 0x00 : 0x40;
|
||||
|
||||
case 0x48: // p1
|
||||
|
@ -386,7 +386,7 @@ void s14001a_start_write(INT32 state)
|
||||
void s14001a_set_clock(INT32 clock)
|
||||
{
|
||||
chip.clock = clock;
|
||||
stream.set_rate(clock, 1);
|
||||
stream.set_rate(clock);
|
||||
}
|
||||
|
||||
void s14001a_set_volume(double volume)
|
||||
|
@ -42,6 +42,8 @@ struct Stream {
|
||||
#define MAX_CHANNELS 8
|
||||
INT32 nChannels;
|
||||
bool bAddStream;
|
||||
bool bRateChange;
|
||||
UINT32 nNewRate;
|
||||
|
||||
INT16 *in_buffer[MAX_CHANNELS]; // resampler in-buffers
|
||||
INT32 out_buffer_size;
|
||||
@ -52,20 +54,18 @@ struct Stream {
|
||||
nSampleRateFrom = rate_from;
|
||||
nSampleRateTo = rate_to;
|
||||
nChannels = channels;
|
||||
set_rate(rate_from);
|
||||
set_rate_internal(rate_from);
|
||||
|
||||
stream_init(update_stream);
|
||||
}
|
||||
void set_rate(INT32 rate_from, INT32 reposit_last_rate = 0) {
|
||||
if (reposit_last_rate) {
|
||||
// hack: if rate changes multiple times/frame, approximate new stream position
|
||||
nPosition = nPosition * rate_from / nSampleRateFrom;
|
||||
void set_rate(INT32 rate_from) {
|
||||
bRateChange = true;
|
||||
nNewRate = rate_from;
|
||||
}
|
||||
void set_rate_internal(INT32 rate_from) {
|
||||
nSampleRateFrom = rate_from;
|
||||
nSampleSize = (UINT64)nSampleRateFrom * (1 << 16) / ((nSampleRateTo == 0) ? 44100 : nSampleRateTo);
|
||||
nSampleSize_Otherway = (UINT64)((nSampleRateTo == 0) ? 44100 : nSampleRateTo) * (1 << 16) / ((nSampleRateFrom == 0) ? 44100 : nSampleRateFrom);
|
||||
// origially this restarted the frame (nPosition = 0), but this breaks
|
||||
// qbert, as the game writes rate changes several times per frame.
|
||||
}
|
||||
void exit() {
|
||||
nSampleSize = nFractionalPosition = 0;
|
||||
@ -116,6 +116,10 @@ struct Stream {
|
||||
// mask off the whole samples from our accumulator
|
||||
nFractionalPosition &= 0xffff;
|
||||
|
||||
if (bRateChange) {
|
||||
set_rate_internal(nNewRate);
|
||||
bRateChange = false;
|
||||
}
|
||||
}
|
||||
void samplesample(INT16 *out_buffer, INT32 samples) {
|
||||
for (INT32 i = 0; i < samples; i++, out_buffer += 2, nFractionalPosition += nSampleSize) {
|
||||
|
Loading…
Reference in New Issue
Block a user