ref: 9e8c8455544da882e2ebf9f3bc33132f76c4914d
parent: 5165bd20c0353921c7aae4be68641ab718c8752f
author: Olav Sørensen <olav.sorensen@live.no>
date: Sun Mar 13 15:11:11 EDT 2022
Fix (rarely audible) click bug in BLEP synthesis Fixes random clicks in specific pitch sweep tests I made. These clicks shouldn't have been present. This bug was introduced in v1.34.
--- a/src/pt2_audio.c
+++ b/src/pt2_audio.c
@@ -284,12 +284,13 @@
v->dOldVoiceDeltaMul = 1.0 / v->dOldVoiceDelta;
}
+ // to be read on next sampling step
v->AUD_PER_delta = v->dOldVoiceDelta;
-
+ v->AUD_PER_deltamul = v->dOldVoiceDeltaMul;
+
// set BLEP stuff
- v->dDeltaMul = v->dOldVoiceDeltaMul;
- if (v->dLastDelta == 0.0)
- v->dLastDelta = v->AUD_PER_delta;
+ if (v->dLastDelta == 0.0) v->dLastDelta = v->AUD_PER_delta;
+ if (v->dLastDeltaMul == 0.0) v->dLastDeltaMul = v->AUD_PER_deltamul;
}
void paulaSetVolume(int32_t ch, uint16_t vol)
@@ -385,8 +386,10 @@
v->sampleCounter--;
// set BLEP stuff
+ v->dDeltaMul = v->AUD_PER_deltamul;
v->dLastPhase = 0.0;
v->dLastDelta = v->dDelta;
+ v->dLastDeltaMul = v->dDeltaMul;
v->dBlepOffset = 0.0;
v->dPhase = 0.0;
@@ -473,8 +476,15 @@
{
v->dPhase -= 1.0;
+ // set BLEP stuff
+ v->dLastPhase = v->dPhase;
+ v->dLastDelta = v->dDelta;
+ v->dLastDeltaMul = v->dDeltaMul;
+ v->dBlepOffset = v->dLastPhase * v->dLastDeltaMul;
+
// Paula only updates period (delta) during period refetching (this stage)
v->dDelta = v->AUD_PER_delta;
+ v->dDeltaMul = v->AUD_PER_deltamul;
if (v->sampleCounter == 0)
{
@@ -495,7 +505,7 @@
/* Pre-compute current sample point.
** Output volume is only read from AUDxVOL at this stage,
** and we don't emulate volume PWM anyway, so we can
- ** pre-multiply by volume at this point.
+ ** pre-multiply by volume here.
*/
v->dSample = v->AUD_DAT[0] * v->AUD_VOL; // -128..127 * 0.0 .. 1.0
@@ -502,11 +512,6 @@
// progress AUD_DAT buffer
v->AUD_DAT[0] = v->AUD_DAT[1];
v->sampleCounter--;
-
- // setup BLEP stuff
- v->dBlepOffset = v->dPhase * v->dDeltaMul;
- v->dLastPhase = v->dPhase;
- v->dLastDelta = v->dDelta;
}
}
}
--- a/src/pt2_audio.h
+++ b/src/pt2_audio.h
@@ -37,13 +37,13 @@
// registers modified by Paula functions
const int8_t* AUD_LC; // location
uint16_t AUD_LEN; // length (in words)
- double AUD_PER_delta; // delta
+ double AUD_PER_delta, AUD_PER_deltamul; // delta
double AUD_VOL; // volume
double dDelta, dPhase;
// for BLEP synthesis
- double dLastDelta, dLastPhase, dBlepOffset, dDeltaMul;
+ double dLastDelta, dLastPhase, dLastDeltaMul, dBlepOffset, dDeltaMul;
// period cache
int32_t oldPeriod;
--- a/src/pt2_header.h
+++ b/src/pt2_header.h
@@ -14,7 +14,7 @@
#include "pt2_unicode.h"
#include "pt2_palette.h"
-#define PROG_VER_STR "1.41"
+#define PROG_VER_STR "1.42"
#ifdef _WIN32
#define DIR_DELIMITER '\\'