History

Some cleanup and changing of comments

Olav Sørensen committed 5 years ago

Commit 2d2ef291 parent 4d87aa42 files · +28 −23Browse files

Unified · Split

2 files
  1. src/ft2_replayer.c +26 −22
  2. src/ft2_replayer.h +2 −1
src/ft2_replayer.c+26−22
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 */
2929
3030 // non-FT2 precalced stuff (these are kinda big...)
31−static double dPeriod2HzTab[65536], dLogTab[768], dLogMulTab[32], dHz2MixDeltaMul;
31+static double dPeriod2HzTab[65536], dLogTab[768], dExp2MulTab[32], dHz2MixDeltaMul;
3232 static uint32_t revMixDeltaTab[65536];
3333 static bool bxxOverflow;
3434 static tonTyp nilPatternLine[MAX_VOICES];
@@ -274,9 +274,8 @@ static void calcPeriod2HzTable(void) // called every time "linear/amiga frequenc · 239 unmodified lines
274274 const uint16_t invPeriod = (12 * 192 * 4) - (uint16_t)i; // this intentionally 16-bit-underflows to be accurate to FT2
275275 const int32_t octave = invPeriod / 768;
276276 const int32_t period = invPeriod % 768;
277− const int32_t invOct = (14 - octave) & 0x1F; // accurate to FT2
278277
279− dPeriod2HzTab[i] = dLogTab[period] * dLogMulTab[invOct]; // x = y / 2^invOct
278+ dPeriod2HzTab[i] = dLogTab[period] * dExp2MulTab[(14-octave) & 31]; // x = y >> ((14-octave) & 31)
280279 }
281280 }
282281 else
@@ -314,10 +313,10 @@ void calcRevMixDeltaTable(void) · 31 unmodified lines
314313 double getSampleC4Rate(sampleTyp *s)
315314 {
316315 int32_t note = (96/2) + s->relTon;
317− if (note >= (12*10)-1)
316+ if (note >= (10*12)-1)
318317 return -1; // B-9 (from relTon) = illegal! (won't play in replayer)
319318
320− const int32_t C4Period = (note * 16) + (((int8_t)s->fine >> 3) + 16);
319+ const int32_t C4Period = (note << 4) + (((int8_t)s->fine >> 3) + 16);
321320
322321 const uint16_t period = audio.linearFreqTable ? linearPeriods[C4Period] : amigaPeriods[C4Period];
323322 return dPeriod2Hz(period);
@@ -430,11 +429,11 @@ void keyOff(stmTyp *ch) · 106 unmodified lines
430429
431430 void calcReplayerLogTab(void)
432431 {
433− for (uint32_t i = 0; i < 32; i++)
434− dLogMulTab[i] = 1.0 / (1UL << i);
432+ for (int32_t i = 0; i < 32; i++)
433+ dExp2MulTab[i] = 1.0 / exp2(i); // 1/2^i
435434
436435 for (int32_t i = 0; i < 768; i++)
437− dLogTab[i] = exp2(i * (1.0 / 768.0)) * (8363.0 * 256.0);
436+ dLogTab[i] = 8363.0 * 256.0 * exp2(i * (1.0 / 768.0));
438437 }
439438
440439 void calcReplayerVars(int32_t audioFreq)
@@ -562,7 +561,7 @@ static void startTone(uint8_t ton, uint8_t effTyp, uint8_t eff, stmTyp *ch) · 121 unmodified lines
562561 ch->relTonNr = s->relTon;
563562
564563 ton += ch->relTonNr;
565− if (ton >= 12*10)
564+ if (ton >= 10*12)
566565 return;
567566
568567 ch->oldVol = s->vol;
@@ -598,7 +597,7 @@ static void startTone(uint8_t ton, uint8_t effTyp, uint8_t eff, stmTyp *ch) · 29 unmodified lines
598597 }
599598 }
600599
601−static void volume(stmTyp *ch, uint8_t param); // actually volume slide
600+static void volume(stmTyp *ch, uint8_t param); // volume slide
602601 static void vibrato2(stmTyp *ch);
603602 static void tonePorta(stmTyp *ch, uint8_t param);
604603
@@ -632,8 +631,8 @@ static void finePortaDown(stmTyp *ch, uint8_t param) · 27 unmodified lines
632631 ch->fPortaDownSpeed = param;
633632
634633 ch->realPeriod += param << 2;
635− if ((int16_t)ch->realPeriod > 32000-1)
636− ch->realPeriod = 32000-1;
634+ if ((int16_t)ch->realPeriod > MAX_FRQ-1) // FT2 bug, should've been unsigned comparison
635+ ch->realPeriod = MAX_FRQ-1;
637636
638637 ch->outPeriod = ch->realPeriod;
639638 ch->status |= IS_Period;
@@ -1181,8 +1180,8 @@ static void xFinePorta(stmTyp *ch, uint8_t param) · 541 unmodified lines
11811180 uint16_t newPeriod = ch->realPeriod;
11821181
11831182 newPeriod += param;
1184− if ((int16_t)newPeriod > 32000-1)
1185− newPeriod = 32000-1;
1183+ if ((int16_t)newPeriod > MAX_FRQ-1) // FT2 bug, should've been unsigned comparison
1184+ newPeriod = MAX_FRQ-1;
11861185
11871186 ch->outPeriod = ch->realPeriod = newPeriod;
11881187 ch->status |= IS_Period;
@@ -1696,7 +1695,7 @@ static void fixaEnvelopeVibrato(stmTyp *ch) · 507 unmodified lines
16961695 uint16_t tmpPeriod = (autoVibVal * (int16_t)autoVibAmp) >> 16;
16971696
16981697 tmpPeriod += ch->outPeriod;
1699− if (tmpPeriod > 32000-1)
1698+ if (tmpPeriod > MAX_FRQ-1)
17001699 tmpPeriod = 0; // yes, FT2 does this (!)
17011700
17021701 #ifdef HAS_MIDI
@@ -1727,7 +1726,12 @@ static uint16_t relocateTon(uint16_t period, uint8_t arpNote, stmTyp *ch) · 24 unmodified lines
17271726 int32_t tmpPeriod;
17281727
17291728 const int32_t fineTune = ((int8_t)ch->fineTune >> 3) + 16;
1730− int32_t hiPeriod = 1536; // FT2 bug: should've been 1935
1729+
1730+ /* FT2 bug, should've been 10*12*16. Notes above B-7 (95) will have issues.
1731+ ** You can only achieve such high notes by having a high relative note setting.
1732+ */
1733+ int32_t hiPeriod = 8*12*16;
1734+
17311735 int32_t loPeriod = 0;
17321736
17331737 for (int32_t i = 0; i < 8; i++)
@@ -1736,7 +1740,7 @@ static uint16_t relocateTon(uint16_t period, uint8_t arpNote, stmTyp *ch) · 2 unmodified lines
17361740
17371741 int32_t lookUp = tmpPeriod - 8;
17381742 if (lookUp < 0)
1739− lookUp = 0; // 8bitbubsy: safety fix (C-0 w/ finetune <= -65)
1743+ lookUp = 0; // safety fix (C-0 w/ finetune <= -65). This buggy read seems to return 0 in FT2 (TODO: Verify...)
17401744
17411745 if (period >= note2Period[lookUp])
17421746 hiPeriod = (tmpPeriod - fineTune) & ~15;
@@ -1745,8 +1749,8 @@ static uint16_t relocateTon(uint16_t period, uint8_t arpNote, stmTyp *ch) · 2 unmodified lines
17451749 }
17461750
17471751 tmpPeriod = loPeriod + fineTune + (arpNote << 4);
1748− if (tmpPeriod >= 1550) // FT2 bugs: off-by-one edge case, and should've been 1935 (1936)
1749− tmpPeriod = 1551;
1752+ if (tmpPeriod >= (8*12*16+15)-1) // FT2 bug, should've been 10*12*16+16 (also notice the +2 difference)
1753+ tmpPeriod = (8*12*16+16)-1;
17501754
17511755 return note2Period[tmpPeriod];
17521756 }
@@ -1829,8 +1833,8 @@ static void portaDown(stmTyp *ch, uint8_t param) · 76 unmodified lines
18291833 ch->portaDownSpeed = param;
18301834
18311835 ch->realPeriod += param << 2;
1832− if ((int16_t)ch->realPeriod > 32000-1) // FT2 bug, should've been unsigned comparison
1833− ch->realPeriod = 32000-1;
1836+ if ((int16_t)ch->realPeriod > MAX_FRQ-1) // FT2 bug, should've been unsigned comparison
1837+ ch->realPeriod = MAX_FRQ-1;
18341838
18351839 ch->outPeriod = ch->realPeriod;
18361840 ch->status |= IS_Period;
@@ -1959,7 +1963,7 @@ static void tremolo(stmTyp *ch, uint8_t param) · 122 unmodified lines
19591963 ch->tremPos += ch->tremSpeed;
19601964 }
19611965
1962−static void volume(stmTyp *ch, uint8_t param) // actually volume slide
1966+static void volume(stmTyp *ch, uint8_t param) // volume slide
19631967 {
19641968 if (param == 0)
19651969 param = ch->volSlideSpeed;
src/ft2_replayer.h+2−1
@@ -42,7 +42,8 @@ enum · 41 unmodified lines
4242 #define MAX_BPM 999
4343 #define MAX_VOICES 32
4444 #define TRACK_WIDTH (5 * MAX_VOICES)
45−#define MAX_NOTES ((12 * 10 * 16) + 16)
45+#define MAX_FRQ 32000
46+#define MAX_NOTES (10*12*16+16)
4647 #define MAX_PATTERNS 256
4748 #define MAX_PATT_LEN 256
4849 #define MAX_INST 128

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t