shithub: ft²

Download patch

ref: 4ae53338b2c79a453c5122bd7eb8f18c592a1c08
parent: e3158f5e1e68ae8649644a36a7ce7b2c31098d8f
author: Olav Sørensen <olav.sorensen@live.no>
date: Fri Mar 3 09:06:03 EST 2023

Some code cleanup

--- a/src/ft2_audio.c
+++ b/src/ft2_audio.c
@@ -188,9 +188,6 @@
 	// for audio/video sync timestamp
 	tickTimeLenInt = audio.tickTimeIntTab[i];
 	tickTimeLenFrac = audio.tickTimeFracTab[i];
-
-	// for calculating volume ramp length for tick-length ramps
-	audio.fRampTickMul = audio.fRampTickMulTab[i];
 }
 
 void audioSetVolRamp(bool volRamp)
@@ -244,13 +241,12 @@
 
 			*f = *v; // copy voice
 
-			f->volumeRampLength = audio.quickVolRampSamples;
-
 			const float fVolumeLTarget = -f->fVolumeL;
 			const float fVolumeRTarget = -f->fVolumeR;
 
-			f->fVolumeLDelta = fVolumeLTarget * audio.fRampQuickVolMul;
-			f->fVolumeRDelta = fVolumeRTarget * audio.fRampQuickVolMul;
+			f->volumeRampLength = audio.quickVolRampSamples;
+			f->fVolumeLDelta = fVolumeLTarget / (int32_t)f->volumeRampLength;
+			f->fVolumeRDelta = fVolumeRTarget / (int32_t)f->volumeRampLength;
 
 			f->isFadeOutVoice = true;
 		}
@@ -279,16 +275,15 @@
 
 		if (status & IS_QuickVol)
 		{
-			v->fVolumeLDelta = fVolumeLTarget * audio.fRampQuickVolMul;
-			v->fVolumeRDelta = fVolumeRTarget * audio.fRampQuickVolMul;
 			v->volumeRampLength = audio.quickVolRampSamples;
-
+			v->fVolumeLDelta = fVolumeLTarget / (int32_t)v->volumeRampLength;
+			v->fVolumeRDelta = fVolumeRTarget / (int32_t)v->volumeRampLength;
 		}
 		else
 		{
-			v->fVolumeLDelta = fVolumeLTarget * audio.fRampTickMul;
-			v->fVolumeRDelta = fVolumeRTarget * audio.fRampTickMul;
 			v->volumeRampLength = audio.samplesPerTickInt;
+			v->fVolumeLDelta = fVolumeLTarget / (int32_t)v->volumeRampLength;
+			v->fVolumeRDelta = fVolumeRTarget / (int32_t)v->volumeRampLength;
 		}
 	}
 }
@@ -1048,7 +1043,7 @@
 	double dFrac = modf(dAudioLatencySecs * editor.dPerfFreq, &dInt);
 
 	audio.audLatencyPerfValInt = (uint32_t)dInt;
-	audio.audLatencyPerfValFrac = (uint64_t)((dFrac * TICK_TIME_FRAC_SCALE) + 0.5);
+	audio.audLatencyPerfValFrac = (uint64_t)((dFrac * TICK_TIME_FRAC_SCALE) + 0.5); // rounded
 
 	audio.dAudioLatencyMs = dAudioLatencySecs * 1000.0;
 }
--- a/src/ft2_audio.h
+++ b/src/ft2_audio.h
@@ -45,7 +45,7 @@
 	bool linearPeriodsFlag, rescanAudioDevicesSupported;
 	volatile uint8_t interpolationType;
 	int32_t quickVolRampSamples, inputDeviceNum, outputDeviceNum, lastWorkingAudioFreq, lastWorkingAudioBits;
-	uint32_t freq, musicTimeSpeedVal;
+	uint32_t freq;
 
 	uint32_t tickSampleCounter, samplesPerTickInt, samplesPerTickIntTab[(MAX_BPM-MIN_BPM)+1];
 	uint64_t tickSampleCounterFrac, samplesPerTickFrac, samplesPerTickFracTab[(MAX_BPM-MIN_BPM)+1];
@@ -55,7 +55,6 @@
 
 	uint64_t tickTime64, tickTime64Frac;
 
-	float fRampQuickVolMul, fRampTickMul, fRampTickMulTab[(MAX_BPM-MIN_BPM)+1];
 	float *fMixBufferL, *fMixBufferR;
 	double dHz2MixDeltaMul, dAudioLatencyMs;
 
--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -12,7 +12,7 @@
 #endif
 #include "ft2_replayer.h"
 
-#define PROG_VER_STR "1.64"
+#define PROG_VER_STR "1.65"
 
 // do NOT change these! It will only mess things up...
 
--- a/src/ft2_replayer.c
+++ b/src/ft2_replayer.c
@@ -415,7 +415,6 @@
 
 	audio.dHz2MixDeltaMul = (double)MIXER_FRAC_SCALE / audioFreq;
 	audio.quickVolRampSamples = (int32_t)round(audioFreq / (double)FT2_QUICKRAMP_SAMPLES);
-	audio.fRampQuickVolMul = (float)(1.0 / audio.quickVolRampSamples);
 
 	for (int32_t bpm = MIN_BPM; bpm <= MAX_BPM; bpm++)
 	{
@@ -435,11 +434,7 @@
 		double dTimeFrac = modf(editor.dPerfFreq / dBpmHz, &dTimeInt);
 
 		audio.tickTimeIntTab[i] = (uint32_t)dTimeInt;
-		audio.tickTimeFracTab[i] = (uint64_t)((dTimeFrac * TICK_TIME_FRAC_SCALE) + 0.5);
-
-		// for calculating volume ramp length for tick-lenghted ramps
-		const int32_t samplesPerTickRounded = (int32_t)(dSamplesPerTick + 0.5); // must be rounded
-		audio.fRampTickMulTab[i] = (float)(1.0 / samplesPerTickRounded);
+		audio.tickTimeFracTab[i] = (uint64_t)((dTimeFrac * TICK_TIME_FRAC_SCALE) + 0.5); // rounded
 	}
 }