Skip to content

Commit 9e8c845

Browse files
committed
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.
1 parent 5165bd2 commit 9e8c845

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/pt2_audio.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,13 @@ void paulaSetPeriod(int32_t ch, uint16_t period)
284284
v->dOldVoiceDeltaMul = 1.0 / v->dOldVoiceDelta;
285285
}
286286

287+
// to be read on next sampling step
287288
v->AUD_PER_delta = v->dOldVoiceDelta;
288-
289+
v->AUD_PER_deltamul = v->dOldVoiceDeltaMul;
290+
289291
// set BLEP stuff
290-
v->dDeltaMul = v->dOldVoiceDeltaMul;
291-
if (v->dLastDelta == 0.0)
292-
v->dLastDelta = v->AUD_PER_delta;
292+
if (v->dLastDelta == 0.0) v->dLastDelta = v->AUD_PER_delta;
293+
if (v->dLastDeltaMul == 0.0) v->dLastDeltaMul = v->AUD_PER_deltamul;
293294
}
294295

295296
void paulaSetVolume(int32_t ch, uint16_t vol)
@@ -385,8 +386,10 @@ void paulaStartDMA(int32_t ch)
385386
v->sampleCounter--;
386387

387388
// set BLEP stuff
389+
v->dDeltaMul = v->AUD_PER_deltamul;
388390
v->dLastPhase = 0.0;
389391
v->dLastDelta = v->dDelta;
392+
v->dLastDeltaMul = v->dDeltaMul;
390393
v->dBlepOffset = 0.0;
391394

392395
v->dPhase = 0.0;
@@ -473,8 +476,15 @@ void mixChannels(int32_t numSamples)
473476
{
474477
v->dPhase -= 1.0;
475478

479+
// set BLEP stuff
480+
v->dLastPhase = v->dPhase;
481+
v->dLastDelta = v->dDelta;
482+
v->dLastDeltaMul = v->dDeltaMul;
483+
v->dBlepOffset = v->dLastPhase * v->dLastDeltaMul;
484+
476485
// Paula only updates period (delta) during period refetching (this stage)
477486
v->dDelta = v->AUD_PER_delta;
487+
v->dDeltaMul = v->AUD_PER_deltamul;
478488

479489
if (v->sampleCounter == 0)
480490
{
@@ -495,18 +505,13 @@ void mixChannels(int32_t numSamples)
495505
/* Pre-compute current sample point.
496506
** Output volume is only read from AUDxVOL at this stage,
497507
** and we don't emulate volume PWM anyway, so we can
498-
** pre-multiply by volume at this point.
508+
** pre-multiply by volume here.
499509
*/
500510
v->dSample = v->AUD_DAT[0] * v->AUD_VOL; // -128..127 * 0.0 .. 1.0
501511

502512
// progress AUD_DAT buffer
503513
v->AUD_DAT[0] = v->AUD_DAT[1];
504514
v->sampleCounter--;
505-
506-
// setup BLEP stuff
507-
v->dBlepOffset = v->dPhase * v->dDeltaMul;
508-
v->dLastPhase = v->dPhase;
509-
v->dLastDelta = v->dDelta;
510515
}
511516
}
512517
}

src/pt2_audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ typedef struct voice_t
3737
// registers modified by Paula functions
3838
const int8_t* AUD_LC; // location
3939
uint16_t AUD_LEN; // length (in words)
40-
double AUD_PER_delta; // delta
40+
double AUD_PER_delta, AUD_PER_deltamul; // delta
4141
double AUD_VOL; // volume
4242

4343
double dDelta, dPhase;
4444

4545
// for BLEP synthesis
46-
double dLastDelta, dLastPhase, dBlepOffset, dDeltaMul;
46+
double dLastDelta, dLastPhase, dLastDeltaMul, dBlepOffset, dDeltaMul;
4747

4848
// period cache
4949
int32_t oldPeriod;

src/pt2_header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "pt2_unicode.h"
1515
#include "pt2_palette.h"
1616

17-
#define PROG_VER_STR "1.41"
17+
#define PROG_VER_STR "1.42"
1818

1919
#ifdef _WIN32
2020
#define DIR_DELIMITER '\\'

0 commit comments

Comments
 (0)