ref: 53456ab178ac8f0e9399af1cf87122a2fc479fe8
parent: f8c9eaf54b72e77320cb3ad47bc2526a59e78cee
author: Olav Sørensen <olav.sorensen@live.no>
date: Wed Jan 13 16:23:58 EST 2021
Micro optimizations ;)
--- a/src/ft2_audio.c
+++ b/src/ft2_audio.c
@@ -198,7 +198,7 @@
{
// same formula as FT2's panning table (with 0.0f..1.0f range)
for (int32_t i = 0; i <= 256; i++)
- dPanningTab[i] = sqrt(i / 256.0);
+ dPanningTab[i] = sqrt(i * (1.0 / 256.0));
}
static void voiceUpdateVolumes(int32_t i, uint8_t status)
--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -12,7 +12,7 @@
#endif
#include "ft2_replayer.h"
-#define PROG_VER_STR "1.42"
+#define PROG_VER_STR "1.43"
// do NOT change these! It will only mess things up...
--- a/src/ft2_replayer.h
+++ b/src/ft2_replayer.h
@@ -213,9 +213,12 @@
int16_t midiPitch;
uint16_t outPeriod, realPeriod, finalPeriod, tonTyp, wantPeriod, portaSpeed;
uint16_t envVCnt, envPCnt, eVibAmp, eVibSweep;
- uint16_t fadeOutAmp, fadeOutSpeed, midiVibDepth;
- double dEnvVIPValue, dEnvPIPValue, dEnvVAmp, dEnvPAmp, dFinalVol;
+ uint16_t fadeOutAmp, fadeOutSpeed, midiVibDepth;
+ int32_t envVIPValue, envPIPValue, envVAmp, envPAmp;
int32_t oldFinalPeriod, smpStartPos;
+
+ double dFinalVol;
+
sampleTyp *smpPtr;
instrTyp *instrPtr;
} stmTyp;
@@ -247,6 +250,8 @@
double dFinalVol;
} syncedChannel_t;
+double getSampleC4Rate(sampleTyp *s);
+
void setNewSongPos(int32_t pos);
void resetReplayerState(void);
@@ -253,7 +258,7 @@
void fixSongName(void); // removes spaces from right side of song name
void fixSampleName(int16_t nr); // removes spaces from right side of ins/smp names
void calcReplayerVars(int32_t rate);
-void tuneSample(sampleTyp *s, int32_t midCFreq);
+void tuneSample(sampleTyp *s, const int32_t midCFreq);
void calcRevMixDeltaTable(void);
void calcReplayerLogTab(void);
@@ -262,7 +267,7 @@
int64_t getMixerDelta(uint16_t period);
uint32_t getRevMixerDelta(uint16_t period);
-int32_t getPianoKey(uint16_t period, int32_t finetune, int32_t relativeNote); // for piano in Instr. Ed.
+int32_t getPianoKey(uint16_t period, int8_t finetune, int8_t relativeNote); // for piano in Instr. Ed.
bool allocateInstr(int16_t nr);
void freeInstr(int32_t nr);
--- a/src/ft2_scopes.c
+++ b/src/ft2_scopes.c
@@ -26,9 +26,8 @@
#define SCOPE_HEIGHT 36
static volatile bool scopesUpdatingFlag, scopesDisplayingFlag;
-static int32_t oldPeriod;
-static uint32_t oldDrawDelta, scopeTimeLen, scopeTimeLenFrac;
-static uint64_t oldDelta, timeNext64, timeNext64Frac;
+static uint32_t scopeTimeLen, scopeTimeLenFrac;
+static uint64_t timeNext64, timeNext64Frac;
static volatile scope_t scope[MAX_VOICES];
static SDL_Thread *scopeThread;
@@ -36,9 +35,13 @@
void resetCachedScopeVars(void)
{
- oldPeriod = -1;
- oldDelta = 0;
- oldDrawDelta = 0;
+ volatile scope_t *sc = scope;
+ for (int32_t i = 0; i < MAX_VOICES; i++, sc++)
+ {
+ sc->oldPeriod = -1;
+ sc->oldDrawDelta = 0;
+ sc->oldDelta = 0;
+ }
}
int32_t getSamplePosition(uint8_t ch)
@@ -383,9 +386,14 @@
// scope position update
s.posFrac += s.delta;
- s.pos += (int32_t)(s.posFrac >> SCOPE_FRAC_BITS) * s.direction;
+ const int32_t wholeSamples = (int32_t)(s.posFrac >> SCOPE_FRAC_BITS);
s.posFrac &= SCOPE_FRAC_MASK;
+ if (s.direction == 1)
+ s.pos += wholeSamples; // forwards
+ else
+ s.pos -= wholeSamples; // backwards
+
// handle loop wrapping or sample end
if (s.direction == -1 && s.pos < s.loopStart) // sampling backwards (definitely pingpong loop)
{
@@ -521,20 +529,20 @@
// use cached values if possible
const uint16_t period = ch->finalPeriod;
- if (period != oldPeriod)
+ if (period != sc->oldPeriod)
{
- oldPeriod = period;
+ sc->oldPeriod = period;
const double dHz = dPeriod2Hz(period);
const double dScopeRateFactor = SCOPE_FRAC_SCALE / (double)SCOPE_HZ;
- oldDelta = (int64_t)((dHz * dScopeRateFactor) + 0.5); // Hz -> rounded fixed-point delta
+ sc->oldDelta = (int64_t)((dHz * dScopeRateFactor) + 0.5); // Hz -> rounded fixed-point delta
const double dRelativeHz = dHz * (1.0 / (8363.0 / 2.0));
- oldDrawDelta = (int32_t)((dRelativeHz * SCOPE_DRAW_FRAC_SCALE) + 0.5); // Hz -> rounded fixed-point draw delta
+ sc->oldDrawDelta = (int32_t)((dRelativeHz * SCOPE_DRAW_FRAC_SCALE) + 0.5); // Hz -> rounded fixed-point draw delta
}
- sc->delta = oldDelta;
- sc->drawDelta = oldDrawDelta;
+ sc->delta = sc->oldDelta;
+ sc->drawDelta = sc->oldDrawDelta;
}
if (status & IS_NyTon)
--- a/src/ft2_scopes.h
+++ b/src/ft2_scopes.h
@@ -31,9 +31,9 @@
const int16_t *base16;
bool wasCleared, sampleIs16Bit;
uint8_t loopType;
- int32_t vol, loopStart, loopLength, end, pos, direction;
- uint32_t drawDelta;
- uint64_t delta, posFrac;
+ int32_t vol, loopStart, loopLength, end, pos, direction, oldPeriod;
+ uint32_t drawDelta, oldDrawDelta;
+ uint64_t delta, posFrac, oldDelta;
} scope_t;
typedef struct lastChInstr_t