ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

commit 4ae53338b2c79a453c5122bd7eb8f18c592a1c08
parent e3158f5e1e68ae8649644a36a7ce7b2c31098d8f
Author: Olav Sørensen <olav.sorensen@live.no>
Date:   Fri,  3 Mar 2023 14:05:36 +0100

Some code cleanup

Diffstat:
Msrc/ft2_audio.c | 21++++++++-------------
Msrc/ft2_audio.h | 3+--
Msrc/ft2_header.h | 2+-
Msrc/ft2_replayer.c | 7+------
4 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/src/ft2_audio.c b/src/ft2_audio.c @@ -188,9 +188,6 @@ void setMixerBPM(int32_t bpm) // 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 @@ static void voiceUpdateVolumes(int32_t i, uint8_t status) *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 @@ static void voiceUpdateVolumes(int32_t i, uint8_t status) 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 @@ static void calcAudioLatencyVars(int32_t audioBufferSize, int32_t audioFreq) 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; } diff --git a/src/ft2_audio.h b/src/ft2_audio.h @@ -45,7 +45,7 @@ typedef struct audio_t 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 @@ typedef struct audio_t uint64_t tickTime64, tickTime64Frac; - float fRampQuickVolMul, fRampTickMul, fRampTickMulTab[(MAX_BPM-MIN_BPM)+1]; float *fMixBufferL, *fMixBufferR; double dHz2MixDeltaMul, dAudioLatencyMs; diff --git 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... diff --git a/src/ft2_replayer.c b/src/ft2_replayer.c @@ -415,7 +415,6 @@ void calcReplayerVars(int32_t audioFreq) 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 @@ void calcReplayerVars(int32_t audioFreq) 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 } }