ref: e9ac0d503d678604c822dd75aa8805fb40aef874
parent: f0cc39bf0859cec692fbad1431b2c176fb14b4fb
author: Olav Sørensen <olav.sorensen@live.no>
date: Wed Sep 17 16:07:24 EDT 2025
Code cleanup
--- a/src/ft2_audio.c
+++ b/src/ft2_audio.c
@@ -237,11 +237,10 @@
// now we need to handle volume ramping
- const bool voiceSampleTrigger = !!(status & IS_Trigger);
-
- if (voiceSampleTrigger)
+ const bool voiceTriggerFlag = !!(status & CS_TRIGGER_VOICE);
+ if (voiceTriggerFlag)
{- // sample is about to start, ramp out/in at the same time
+ // voice is about to start, ramp out/in at the same time
if (v->fCurrVolumeL > 0.0f || v->fCurrVolumeR > 0.0f)
{@@ -265,7 +264,7 @@
v->fCurrVolumeL = v->fCurrVolumeR = 0.0f;
}
- if (!voiceSampleTrigger && v->fTargetVolumeL == v->fCurrVolumeL && v->fTargetVolumeR == v->fCurrVolumeR)
+ if (!voiceTriggerFlag && v->fTargetVolumeL == v->fCurrVolumeL && v->fTargetVolumeR == v->fCurrVolumeR)
{v->volumeRampLength = 0; // no ramp needed for now
}
@@ -275,7 +274,7 @@
const float fVolumeRDiff = v->fTargetVolumeR - v->fCurrVolumeR;
float fRampLengthMul;
- if (status & IS_QuickVol) // duration of 5ms
+ if (status & CS_USE_QUICK_VOLRAMP) // 5ms duration
{v->volumeRampLength = audio.quickVolRampSamples;
fRampLengthMul = audio.fQuickVolRampSamplesMul;
@@ -368,19 +367,19 @@
ch->status = 0;
- if (status & IS_Vol)
+ if (status & CS_UPDATE_VOL)
{v->fVolume = ch->fFinalVol; // 0.0f .. 1.0f
v->scopeVolume = (uint8_t)((ch->fFinalVol * (SCOPE_HEIGHT*4.0f)) + 0.5f);
}
- if (status & IS_Pan)
+ if (status & CS_UPDATE_PAN)
v->panning = ch->finalPan;
- if (status & (IS_Vol + IS_Pan))
+ if (status & (CS_UPDATE_VOL + CS_UPDATE_PAN)) // for vol and/or pan updates
voiceUpdateVolumes(i, status);
- if (status & IS_Period)
+ if (status & CF_UPDATE_PERIOD)
{const double dVoiceHz = dPeriod2Hz(ch->finalPeriod);
@@ -398,7 +397,7 @@
}
}
- if (status & IS_Trigger)
+ if (status & CS_TRIGGER_VOICE)
voiceTrigger(i, ch->smpPtr, ch->smpStartPos);
}
}
@@ -806,7 +805,7 @@
c->smpStartPos = s->smpStartPos;
c->pianoNoteNum = 255; // no piano key
- if (songPlaying && ui.instEditorShown && (c->status & IS_Period) && !s->keyOff)
+ if (songPlaying && ui.instEditorShown && (c->status & CF_UPDATE_PERIOD) && !s->keyOff)
{const int32_t note = getPianoKey(s->finalPeriod, s->finetune, s->relativeNote);
if (note >= 0 && note <= 95)
--- a/src/ft2_replayer.c
+++ b/src/ft2_replayer.c
@@ -99,7 +99,7 @@
ch = channel;
for (int32_t i = 0; i < song.numChannels; i++, ch++)
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
}
@@ -115,7 +115,7 @@
for (int32_t i = 0; i < MAX_CHANNELS; i++, ch++)
{ch->instrPtr = instr[0];
- ch->status = IS_Vol;
+ ch->status = CS_UPDATE_VOL;
ch->oldPan = 128;
ch->outPan = 128;
ch->finalPan = 128;
@@ -308,7 +308,7 @@
ch->outVol = ch->oldVol;
ch->outPan = ch->oldPan;
- ch->status |= IS_Vol + IS_Pan + IS_QuickVol;
+ ch->status |= CS_UPDATE_VOL + CS_UPDATE_PAN + CS_USE_QUICK_VOLRAMP;
}
void triggerInstrument(channel_t *ch)
@@ -376,7 +376,7 @@
{ch->realVol = 0;
ch->outVol = 0;
- ch->status |= IS_Vol + IS_QuickVol;
+ ch->status |= CS_UPDATE_VOL + CS_USE_QUICK_VOLRAMP;
}
if (!(ins->panEnvFlags & ENV_ENABLED)) // FT2 logic bug!
@@ -522,7 +522,7 @@
ch->outPeriod = ch->realPeriod = note2PeriodLUT[noteIndex];
}
- ch->status |= IS_Period + IS_Vol + IS_Pan + IS_Trigger + IS_QuickVol;
+ ch->status |= CF_UPDATE_PERIOD + CS_UPDATE_VOL + CS_UPDATE_PAN + CS_TRIGGER_VOICE + CS_USE_QUICK_VOLRAMP;
if (efx == 9) // 9xx (Set Sample Offset)
{@@ -560,7 +560,7 @@
ch->realPeriod = 1;
ch->outPeriod = ch->realPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
static void finePitchSlideDown(channel_t *ch, uint8_t param)
@@ -575,12 +575,12 @@
ch->realPeriod = 32000-1;
ch->outPeriod = ch->realPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
static void setPortamentoCtrl(channel_t *ch, uint8_t param)
{- ch->portaSemitoneSlides = (param != 0);
+ ch->semitonePortaMode = (param != 0);
}
static void setVibratoCtrl(channel_t *ch, uint8_t param)
@@ -625,7 +625,7 @@
ch->realVol = 64;
ch->outVol = ch->realVol;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
static void fineVolFineDown(channel_t *ch, uint8_t param)
@@ -640,7 +640,7 @@
ch->realVol = 0;
ch->outVol = ch->realVol;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
static void noteCut0(channel_t *ch, uint8_t param)
@@ -649,7 +649,7 @@
{ch->realVol = 0;
ch->outVol = 0;
- ch->status |= IS_Vol + IS_QuickVol;
+ ch->status |= CS_UPDATE_VOL + CS_USE_QUICK_VOLRAMP;
}
}
@@ -754,7 +754,7 @@
// update all voice volumes
channel_t *c = channel;
for (int32_t i = 0; i < song.numChannels; i++, c++)
- c->status |= IS_Vol;
+ c->status |= CS_UPDATE_VOL;
(void)ch;
}
@@ -973,7 +973,7 @@
*volColumnData = 64;
ch->outVol = ch->realVol = *volColumnData;
- ch->status |= IS_Vol + IS_QuickVol;
+ ch->status |= CS_UPDATE_VOL + CS_USE_QUICK_VOLRAMP;
}
static void v_FineVolSlideDown(channel_t *ch, uint8_t *volColumnData)
@@ -983,7 +983,7 @@
*volColumnData = 0;
ch->outVol = ch->realVol = *volColumnData;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
static void v_FineVolSlideUp(channel_t *ch, uint8_t *volColumnData)
@@ -993,7 +993,7 @@
*volColumnData = 64;
ch->outVol = ch->realVol = *volColumnData;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
static void v_SetPan(channel_t *ch, uint8_t *volColumnData)
@@ -1001,7 +1001,7 @@
*volColumnData <<= 4;
ch->outPan = *volColumnData;
- ch->status |= IS_Pan;
+ ch->status |= CS_UPDATE_PAN;
}
// -- non-tick-zero volume column effects --
@@ -1013,7 +1013,7 @@
newVol = 0;
ch->outVol = ch->realVol = newVol;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
static void v_VolSlideUp(channel_t *ch)
@@ -1023,7 +1023,7 @@
newVol = 64;
ch->outVol = ch->realVol = newVol;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
static void v_Vibrato(channel_t *ch)
@@ -1042,7 +1042,7 @@
tmp16 = 0;
ch->outPan = (uint8_t)tmp16;
- ch->status |= IS_Pan;
+ ch->status |= CS_UPDATE_PAN;
}
static void v_PanSlideRight(channel_t *ch)
@@ -1052,7 +1052,7 @@
tmp16 = 255;
ch->outPan = (uint8_t)tmp16;
- ch->status |= IS_Pan;
+ ch->status |= CS_UPDATE_PAN;
}
static void v_Portamento(channel_t *ch)
@@ -1092,7 +1092,7 @@
static void setPan(channel_t *ch, uint8_t param)
{ch->outPan = param;
- ch->status |= IS_Pan;
+ ch->status |= CS_UPDATE_PAN;
}
static void setVol(channel_t *ch, uint8_t param)
@@ -1101,7 +1101,7 @@
param = 64;
ch->outVol = ch->realVol = param;
- ch->status |= IS_Vol + IS_QuickVol;
+ ch->status |= CS_UPDATE_VOL + CS_USE_QUICK_VOLRAMP;
}
static void extraFinePitchSlide(channel_t *ch, uint8_t param)
@@ -1123,7 +1123,7 @@
newPeriod = 1;
ch->outPeriod = ch->realPeriod = newPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
else if (slideType == 2) // slide down
{@@ -1139,7 +1139,7 @@
newPeriod = 32000-1;
ch->outPeriod = ch->realPeriod = newPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
}
@@ -1280,7 +1280,7 @@
if (ch->efxData > 0) // we have an arpeggio running, set period back
{ch->outPeriod = ch->realPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
}
else
@@ -1289,7 +1289,7 @@
if ((ch->efx == 4 || ch->efx == 6) && (p->efx != 4 && p->efx != 6))
{ch->outPeriod = ch->realPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
}
@@ -1401,7 +1401,7 @@
}
}
- ch->status |= IS_Vol; // always update volume, even if fadeout has reached 0
+ ch->status |= CS_UPDATE_VOL; // always update volume, even if fadeout has reached 0
}
// handle volumes
@@ -1502,7 +1502,7 @@
fVol = vol * (1.0f / (64.0f * 64.0f * 32768.0f));
fVol *= fEnvVal * (1.0f / 64.0f); // volume envelope value
- ch->status |= IS_Vol; // update mixer vol every tick when vol envelope is enabled
+ ch->status |= CS_UPDATE_VOL; // update mixer vol every tick when vol envelope is enabled
}
else
{@@ -1616,7 +1616,7 @@
ch->finalPan = (uint8_t)CLAMP(newPan, 0, 255); // FT2 doesn't clamp the pan, but let's do it anyway
- ch->status |= IS_Pan; // update pan every tick because pan envelope is enabled
+ ch->status |= CS_UPDATE_PAN; // update pan every tick because pan envelope is enabled
}
else
{@@ -1683,7 +1683,7 @@
#endif
ch->finalPeriod = tmpPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
else
{@@ -1693,7 +1693,7 @@
if (midi.enable)
{ch->finalPeriod -= ch->midiPitch;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
#endif
}
@@ -1700,7 +1700,7 @@
}
// for arpeggio and portamento (semitone-slide mode)
-static uint16_t adjustPeriodFromNote(uint16_t period, uint8_t arpNote, channel_t *ch)
+static uint16_t period2NotePeriod(uint16_t period, uint8_t outputNoteOffset, channel_t *ch)
{int32_t tmpPeriod;
@@ -1727,7 +1727,7 @@
loPeriod = (tmpPeriod - fineTune) & ~15;
}
- tmpPeriod = loPeriod + fineTune + (arpNote << 4);
+ tmpPeriod = loPeriod + fineTune + (outputNoteOffset << 4);
if (tmpPeriod >= (8*12*16+15)-1) // FT2 bug, should've been 10*12*16+16 (also notice the +2 difference)
tmpPeriod = (8*12*16+16)-1;
@@ -1763,13 +1763,13 @@
else
ch->outPeriod = ch->realPeriod + tmpVib;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
ch->vibratoPos += ch->vibratoSpeed;
}
static void arpeggio(channel_t *ch, uint8_t param)
{- uint8_t note;
+ uint8_t noteOffset;
const uint8_t tick = arpeggioTab[song.tick & 31];
if (tick == 0)
@@ -1779,14 +1779,14 @@
else
{if (tick == 1)
- note = param >> 4;
+ noteOffset = param >> 4;
else
- note = param & 0x0F; // tick 2
+ noteOffset = param & 0x0F; // tick 2
- ch->outPeriod = adjustPeriodFromNote(ch->realPeriod, note, ch);
+ ch->outPeriod = period2NotePeriod(ch->realPeriod, noteOffset, ch);
}
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
static void pitchSlideUp(channel_t *ch, uint8_t param)
@@ -1801,7 +1801,7 @@
ch->realPeriod = 1;
ch->outPeriod = ch->realPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
static void pitchSlideDown(channel_t *ch, uint8_t param)
@@ -1816,7 +1816,7 @@
ch->realPeriod = 32000-1;
ch->outPeriod = ch->realPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
}
static void portamento(channel_t *ch, uint8_t param)
@@ -1843,12 +1843,12 @@
}
}
- if (ch->portaSemitoneSlides)
- ch->outPeriod = adjustPeriodFromNote(ch->realPeriod, 0, ch);
+ if (ch->semitonePortaMode)
+ ch->outPeriod = period2NotePeriod(ch->realPeriod, 0, ch);
else
ch->outPeriod = ch->realPeriod;
- ch->status |= IS_Period;
+ ch->status |= CF_UPDATE_PERIOD;
(void)param;
}
@@ -1934,7 +1934,7 @@
}
ch->outVol = (uint8_t)tremVol;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
ch->tremoloPos += ch->tremoloSpeed;
}
@@ -1963,7 +1963,7 @@
}
ch->outVol = ch->realVol = newVol;
- ch->status |= IS_Vol;
+ ch->status |= CS_UPDATE_VOL;
}
static void globalVolSlide(channel_t *ch, uint8_t param)
@@ -1995,7 +1995,7 @@
channel_t *c = channel;
for (int32_t i = 0; i < song.numChannels; i++, c++)
- c->status |= IS_Vol;
+ c->status |= CS_UPDATE_VOL;
}
static void keyOffCmd(channel_t *ch, uint8_t param)
@@ -2028,7 +2028,7 @@
}
ch->outPan = (uint8_t)newPan;
- ch->status |= IS_Pan;
+ ch->status |= CS_UPDATE_PAN;
}
static void tremor(channel_t *ch, uint8_t param)
@@ -2058,7 +2058,7 @@
ch->tremorPos = tremorSign | tremorData;
ch->outVol = (tremorSign == 0x80) ? ch->realVol : 0;
- ch->status |= IS_Vol + IS_QuickVol;
+ ch->status |= CS_UPDATE_VOL + CS_USE_QUICK_VOLRAMP;
}
static void retrigNote(channel_t *ch, uint8_t param)
@@ -2078,7 +2078,7 @@
if ((uint8_t)(song.speed-song.tick) == param)
{ch->outVol = ch->realVol = 0;
- ch->status |= IS_Vol + IS_QuickVol;
+ ch->status |= CS_UPDATE_VOL + CS_USE_QUICK_VOLRAMP;
}
}
@@ -3036,7 +3036,7 @@
unlockAudio();
- while (ch->status & IS_Trigger); // wait for sample to latch in mixer
+ while (ch->status & CS_TRIGGER_VOICE); // wait for voice to trigger in mixer
// for sampling playback line in Smp. Ed.
editor.curPlayInstr = editor.curInstr;
@@ -3099,7 +3099,7 @@
unlockAudio();
- while (ch->status & IS_Trigger); // wait for sample to latch in mixer
+ while (ch->status & CS_TRIGGER_VOICE); // wait for voice to trigger in mixer
// for sampling playback line in Smp. Ed.
editor.curPlayInstr = editor.curInstr;
@@ -3124,7 +3124,7 @@
ch->smpPtr = NULL;
ch->instrNum = 0;
ch->instrPtr = instr[0]; // important: set instrument pointer to instr 0 (placeholder instrument)
- ch->status = IS_Vol;
+ ch->status = CS_UPDATE_VOL;
ch->realVol = 0;
ch->outVol = 0;
ch->oldVol = 0;
--- a/src/ft2_replayer.h
+++ b/src/ft2_replayer.h
@@ -9,12 +9,12 @@
enum
{- // voice flags
- IS_Vol = 1, // set volume
- IS_Period = 2, // set resampling rate
- IS_Trigger = 4, // trigger sample
- IS_Pan = 8, // set panning
- IS_QuickVol = 16, // 5ms volramp instead of tick ms
+ // channel/voice status flags
+ CS_UPDATE_VOL = 1,
+ CF_UPDATE_PERIOD = 2,
+ CS_TRIGGER_VOICE = 4,
+ CS_UPDATE_PAN = 8,
+ CS_USE_QUICK_VOLRAMP = 16, // use 5ms vol. ramp instead of the duration of a tick
LOOP_DISABLED = 0,
LOOP_FORWARD = 1,
@@ -240,7 +240,7 @@
typedef struct channel_t
{- bool keyOff, channelOff, mute, portaSemitoneSlides;
+ bool keyOff, channelOff, mute, semitonePortaMode;
volatile uint8_t status, tmpStatus;
int8_t relativeNote, finetune;
uint8_t smpNum, instrNum, efxData, efx, sampleOffset, tremorParam, tremorPos;
--- a/src/ft2_smpfx.c
+++ b/src/ft2_smpfx.c
@@ -777,7 +777,7 @@
ch->realVol = ch->outVol = ch->oldVol = 64;
updateVolPanAutoVib(ch);
- while (ch->status & IS_Trigger); // wait for sample to latch in mixer
+ while (ch->status & CS_TRIGGER_VOICE); // wait for voice to trigger in mixer
SDL_Delay(1500); // wait 1.5 seconds
// we're done, stop voice and free temporary data
--- a/src/scopes/ft2_scopes.c
+++ b/src/scopes/ft2_scopes.c
@@ -82,7 +82,7 @@
ch->outPan = 128;
ch->oldPan = 128;
ch->finalPan = 128;
- ch->status = IS_Vol;
+ ch->status = CS_UPDATE_VOL;
ch->keyOff = true; // non-FT2 bug fix for stuck piano keys
}
@@ -485,10 +485,10 @@
{const uint8_t status = scopeUpdateStatus[i];
- if (status & IS_Vol)
+ if (status & CS_UPDATE_VOL)
sc->volume = ch->scopeVolume;
- if (status & IS_Period)
+ if (status & CF_UPDATE_PERIOD)
{const double dHz = dPeriod2Hz(ch->period);
@@ -496,7 +496,7 @@
sc->drawDelta = (uint64_t)(dHz * (SCOPE_FRAC_SCALE / ((double)C4_FREQ/2.0)));
}
- if (status & IS_Trigger)
+ if (status & CS_TRIGGER_VOICE)
{if (instr[ch->instrNum] != NULL)
{--
⑨