shithub: pt2-clone

Download patch

ref: a342c73ea4e2c18a6c7c3af73a48b8875d7c4056
parent: 8333335001e54764cb306ee1fbf85c40e6e3590e
author: Olav Sørensen <olav.sorensen@live.no>
date: Wed Nov 18 09:39:50 EST 2020

Fix BPM duration issue in PAT2SMP

--- a/src/pt2_pat2smp.c
+++ b/src/pt2_pat2smp.c
@@ -52,22 +52,24 @@
 	modSetTempo(song->currBPM, true);
 	editor.pat2SmpPos = 0;
 
-	double dTickSamples = audio.dSamplesPerTick;
+	double dTickSampleCounter = 0.0;
 
 	editor.smpRenderingDone = false;
-	while (!editor.smpRenderingDone)
+	while (!editor.smpRenderingDone && editor.songPlaying)
 	{
-		const int32_t tickSamples = (int32_t)dTickSamples;
+		if (dTickSampleCounter <= 0.0)
+		{
+			// new replayer tick
 
-		const bool ended = !intMusic() || !editor.songPlaying;
-		outputAudio(NULL, tickSamples);
+			if (!intMusic())
+				editor.smpRenderingDone = true;
 
-		dTickSamples -= tickSamples; // keep fractional part
-		dTickSamples += audio.dSamplesPerTick;
+			dTickSampleCounter += audio.dSamplesPerTick;
+		}
 
-		if (ended)
-			editor.smpRenderingDone = true;
-
+		const int32_t remainingTick = (int32_t)ceil(dTickSampleCounter);
+		outputAudio(NULL, remainingTick);
+		dTickSampleCounter -= remainingTick;
 	}
 	editor.isSMPRendering = false;
 	resetSong();