From 0c5a6d976074f3ad2d3378f680d8467a973bb135 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 13 May 2023 18:54:05 +0900 Subject: [PATCH] Just resample rather than reset --- extern/opl/MODIFIED.md | 2 +- extern/opl/opl3.c | 5 +++++ extern/opl/opl3.h | 1 + src/engine/platform/opl.cpp | 7 ++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/extern/opl/MODIFIED.md b/extern/opl/MODIFIED.md index 78341ad4..d5a39e9f 100644 --- a/extern/opl/MODIFIED.md +++ b/extern/opl/MODIFIED.md @@ -1,4 +1,4 @@ # modification disclaimer -this is a modified version of Nuked-OPL3 which implements channel muting in the core. +this is a modified version of Nuked-OPL3 which implements channel muting in the core, and resampling function. see [this issue](https://github.com/tildearrow/furnace/issues/414) for more information. diff --git a/extern/opl/opl3.c b/extern/opl/opl3.c index 3358f033..5acdca25 100644 --- a/extern/opl/opl3.c +++ b/extern/opl/opl3.c @@ -1362,6 +1362,11 @@ void OPL3_Reset(opl3_chip *chip, uint32_t samplerate) #endif } +void OPL3_Resample(opl3_chip *chip, uint32_t samplerate) +{ + chip->rateratio = (samplerate << RSM_FRAC) / 49716; +} + void OPL3_WriteReg(opl3_chip *chip, uint16_t reg, uint8_t v) { uint8_t high = (reg >> 8) & 0x01; diff --git a/extern/opl/opl3.h b/extern/opl/opl3.h index 8d515323..1e88a801 100644 --- a/extern/opl/opl3.h +++ b/extern/opl/opl3.h @@ -158,6 +158,7 @@ struct _opl3_chip { void OPL3_Generate(opl3_chip *chip, int16_t *buf); void OPL3_GenerateResampled(opl3_chip *chip, int16_t *buf); void OPL3_Reset(opl3_chip *chip, uint32_t samplerate); +void OPL3_Resample(opl3_chip *chip, uint32_t samplerate); void OPL3_WriteReg(opl3_chip *chip, uint16_t reg, uint8_t v); void OPL3_WriteRegBuffered(opl3_chip *chip, uint16_t reg, uint8_t v); void OPL3_GenerateStream(opl3_chip *chip, int16_t *sndptr, uint32_t numsamples); diff --git a/src/engine/platform/opl.cpp b/src/engine/platform/opl.cpp index 3ce997e5..863663a5 100644 --- a/src/engine/platform/opl.cpp +++ b/src/engine/platform/opl.cpp @@ -1866,7 +1866,12 @@ void DivPlatformOPL::setFlags(const DivConfig& flags) { totalOutputs=4; break; } - reset(); + if (downsample) { + const unsigned int downsampledRate=(unsigned int)((double)rate*49716.0/(double)chipRateBase); + OPL3_Resample(&fm,downsampledRate); + } else { + OPL3_Resample(&fm,rate); + } break; case 4: switch (flags.getInt("clockSel",0)) {