History

Code cleanup and render length fix for MOD2WAV

Olav Sørensen committed 5 years ago

Commit 8d634e51 parent 7d3ab131 file · +126 −107Browse files

Unified · Split

src/pt2_replayer.c+126−107
@@ -22,7 +22,7 @@ · 21 unmodified lines
2222 #include "pt2_scopes.h"
2323 #include "pt2_sync.h"
2424
25−static bool posJumpAssert, pBreakFlag, updateUIPositions, modHasBeenPlayed;
25+static bool posJumpAssert, pBreakFlag, modRenderDone;
2626 static int8_t pBreakPosition, oldRow, modPattern;
2727 static uint8_t pattDelTime, lowMask = 0xFF, pattDelTime2;
2828 static int16_t modOrder, oldPattern, oldOrder;
@@ -909,8 +909,38 @@ static void playVoice(moduleChannel_t *ch) · 880 unmodified lines
909909 }
910910 }
911911
912+static bool firstNextPos = true;
913+
914+static void updateUIPositions(void)
915+{
916+ // don't update UI under MOD2WAV/PAT2SMP rendering
917+ if (editor.isWAVRendering || editor.isSMPRendering)
918+ return;
919+
920+ song->currRow = song->row;
921+ song->currOrder = modOrder;
922+ song->currPattern = modPattern;
923+
924+ uint16_t *currPatPtr = &song->header.order[modOrder];
925+ editor.currPatternDisp = currPatPtr;
926+ editor.currPosEdPattDisp = currPatPtr;
927+ editor.currPatternDisp = currPatPtr;
928+ editor.currPosEdPattDisp = currPatPtr;
929+
930+ ui.updateSongPos = true;
931+ ui.updateSongPattern = true;
932+ ui.updateCurrPattText = true;
933+ ui.updatePatternData = true;
934+
935+ if (ui.posEdScreenShown)
936+ ui.updatePosEd = true;
937+}
938+
912939 static void nextPosition(void)
913940 {
941+ if (editor.isSMPRendering)
942+ modRenderDone = true;
943+
914944 song->row = pBreakPosition;
915945 pBreakPosition = 0;
916946 posJumpAssert = false;
@@ -925,9 +955,7 @@ static void nextPosition(void) · 8 unmodified lines
925955 editor.stepPlayEnabled = false;
926956 editor.stepPlayBackwards = false;
927957
928− if (!editor.isWAVRendering && !editor.isSMPRendering)
929− song->currRow = song->row;
930−
958+ song->currRow = song->row;
931959 return;
932960 }
933961
@@ -935,96 +963,101 @@ static void nextPosition(void) · 1 unmodified line
935963 if (modOrder >= song->header.numOrders)
936964 {
937965 modOrder = 0;
938− modHasBeenPlayed = true;
939966
940967 if (config.compoMode) // stop song for music competitions playing
941968 {
942969 doStopIt(true);
943970 turnOffVoices();
944971
945− song->currOrder = 0;
946− song->currRow = song->row = 0;
947− song->currPattern = modPattern = (int8_t)song->header.order[0];
972+ modOrder = 0;
973+ modPattern = (int8_t)song->header.order[modOrder];
974+ song->row = 0;
948975
949− editor.currPatternDisp = &song->currPattern;
950− editor.currPosEdPattDisp = &song->currPattern;
951− editor.currPatternDisp = &song->currPattern;
952− editor.currPosEdPattDisp = &song->currPattern;
953−
954− if (ui.posEdScreenShown)
955− ui.updatePosEd = true;
956−
957− ui.updateSongPos = true;
958− ui.updateSongPattern = true;
959− ui.updateCurrPattText = true;
976+ updateUIPositions();
960977 }
978+
979+ if (editor.isWAVRendering)
980+ modRenderDone = true;
961981 }
962982
963983 modPattern = (int8_t)song->header.order[modOrder];
964984 if (modPattern > MAX_PATTERNS-1)
965985 modPattern = MAX_PATTERNS-1;
966−
967− updateUIPositions = true;
968986 }
987+
988+ firstNextPos = false;
969989 }
970990
971−bool intMusic(void)
991+static void increasePlaybackTimer(void)
972992 {
973− uint8_t i;
974− uint16_t *patt;
975− moduleChannel_t *c;
993+ // the timer is not counting in "play pattern" mode
994+ if (editor.playMode != PLAY_MODE_PATTERN && modBPM >= 32 && modBPM <= 255)
995+ editor.musicTime64 += musicTimeTab64[modBPM-32];
996+}
976997
977− // Quirk: CIA uses newly set timer values on the next interrupt, so handle BPM change now (ciaSetBPM was set on previous interrupt)
978− if (ciaSetBPM != -1)
979− {
980− modSetTempo(ciaSetBPM, false);
981− ciaSetBPM = -1;
982− }
998+static void setCurrRowToVisited(void) // for MOD2WAV
999+{
1000+ if (editor.isWAVRendering)
1001+ editor.rowVisitTable[(modOrder * MOD_ROWS) + song->row] = true;
1002+}
9831003
984− if (editor.playMode != PLAY_MODE_PATTERN && modBPM >= 32 && modBPM <= 255)
985− editor.musicTime64 += musicTimeTab64[modBPM-32]; // for playback counter (don't increase in "play/rec pattern" mode)
1004+static bool renderEndCheck(void) // for MOD2WAV/PAT2SMP
1005+{
1006+ if (!editor.isWAVRendering && !editor.isSMPRendering)
1007+ return true; // we're not doing MOD2WAV/PAT2SMP
9861008
987− if (updateUIPositions)
1009+ bool noPatternDelay = pattDelTime2 == 0;
1010+ if (noPatternDelay && song->tick == song->speed-1)
9881011 {
989− updateUIPositions = false;
990−
991− if (!editor.isWAVRendering && !editor.isSMPRendering)
1012+ if (editor.isSMPRendering)
9921013 {
993− if (editor.playMode != PLAY_MODE_PATTERN)
994− {
995− song->currOrder = modOrder;
996− song->currPattern = modPattern;
997−
998− patt = &song->header.order[modOrder];
999− editor.currPatternDisp = patt;
1000− editor.currPosEdPattDisp = patt;
1001− editor.currPatternDisp = patt;
1002− editor.currPosEdPattDisp = patt;
1014+ if (modRenderDone)
1015+ return false; // we're done rendering
1016+ }
1017+
1018+ if (editor.isWAVRendering)
1019+ {
1020+ bool rowVisited = editor.rowVisitTable[(modOrder * MOD_ROWS) + song->row];
1021+ if (rowVisited || modRenderDone)
1022+ return false; // we're done rendering
1023+ }
1024+ }
10031025
1004− if (ui.posEdScreenShown)
1005− ui.updatePosEd = true;
1026+ return true;
1027+}
10061028
1007− ui.updateSongPos = true;
1008− ui.updateSongPattern = true;
1009− ui.updateCurrPattText = true;
1010− }
1011− }
1029+bool intMusic(void) // replayer ticker
1030+{
1031+ // quirk: CIA BPM changes are delayed by one tick in PT, so handle previous tick's BPM change now
1032+ if (ciaSetBPM != -1)
1033+ {
1034+ const int32_t newBPM = ciaSetBPM;
1035+ modSetTempo(newBPM, false);
1036+ ciaSetBPM = -1;
10121037 }
10131038
1014− if (editor.isWAVRendering && song->tick == 0)
1015− editor.rowVisitTable[(modOrder * MOD_ROWS) + song->row] = true;
1039+ increasePlaybackTimer();
10161040
10171041 if (!editor.stepPlayEnabled)
10181042 song->tick++;
10191043
1020− if ((uint32_t)song->tick >= (uint32_t)song->speed || editor.stepPlayEnabled)
1044+ bool readNewNote = false;
1045+ if ((unsigned)song->tick >= (unsigned)song->speed)
10211046 {
10221047 song->tick = 0;
1048+ readNewNote = true;
1049+ }
10231050
1024− if (pattDelTime2 == 0)
1051+ if (readNewNote || editor.stepPlayEnabled) // tick 0
1052+ {
1053+ if (pattDelTime2 == 0) // no pattern delay, time to read note data
10251054 {
1026− c = song->channels;
1027− for (i = 0; i < AMIGA_VOICES; i++, c++)
1055+ setCurrRowToVisited(); // for MOD2WAV/PAT2SMP
1056+ updateUIPositions(); // update current song positions in UI
1057+
1058+ // read note data and trigger voices
1059+ moduleChannel_t *c = song->channels;
1060+ for (int32_t i = 0; i < AMIGA_VOICES; i++, c++)
10281061 {
10291062 playVoice(c);
10301063 paulaSetVolume(i, c->n_volume);
@@ -1034,23 +1067,18 @@ bool intMusic(void) · 3 unmodified lines
10341067 paulaSetLength(i, c->n_replen);
10351068 }
10361069 }
1037− else
1070+ else // pattern delay is on-going
10381071 {
1039− c = song->channels;
1040− for (i = 0; i < AMIGA_VOICES; i++, c++)
1072+ moduleChannel_t *c = song->channels;
1073+ for (int32_t i = 0; i < AMIGA_VOICES; i++, c++)
10411074 checkEffects(c);
10421075 }
10431076
1044− if (!editor.isWAVRendering && !editor.isSMPRendering)
1045− {
1046− song->currRow = song->row;
1047− ui.updatePatternData = true;
1048− }
1049−
1077+ // increase row
10501078 if (!editor.stepPlayBackwards)
10511079 {
10521080 song->row++;
1053− song->rowsCounter++;
1081+ song->rowsCounter++; // for MOD2WAV's progress bar
10541082 }
10551083
10561084 if (pattDelTime > 0)
@@ -1059,10 +1087,15 @@ bool intMusic(void) · 2 unmodified lines
10591087 pattDelTime = 0;
10601088 }
10611089
1090+ // undo row increase if pattern delay is on-going
10621091 if (pattDelTime2 > 0)
10631092 {
1064− if (--pattDelTime2 > 0)
1093+ pattDelTime2--;
1094+ if (pattDelTime2 > 0)
1095+ {
10651096 song->row--;
1097+ song->rowsCounter--; // for MOD2WAV's progress bar
1098+ }
10661099 }
10671100
10681101 if (pBreakFlag)
@@ -1072,51 +1105,37 @@ bool intMusic(void) · 3 unmodified lines
10721105 pBreakFlag = false;
10731106 }
10741107
1075− if (editor.blockMarkFlag)
1076− ui.updateStatusText = true;
1077−
1108+ // step-play handling
10781109 if (editor.stepPlayEnabled)
10791110 {
10801111 doStopIt(true);
10811112
10821113 song->currRow = song->row & 0x3F;
1083− ui.updatePatternData = true;
1084−
10851114 editor.stepPlayEnabled = false;
10861115 editor.stepPlayBackwards = false;
1087− ui.updatePatternData = true;
10881116
1117+ ui.updatePatternData = true;
10891118 return true;
10901119 }
10911120
10921121 if (song->row >= MOD_ROWS || posJumpAssert)
1093− {
1094− if (editor.isSMPRendering)
1095− modHasBeenPlayed = true;
1096−
10971122 nextPosition();
1098− }
10991123
1100− if (editor.isWAVRendering && !pattDelTime2 && editor.rowVisitTable[(modOrder * MOD_ROWS) + song->row])
1101− modHasBeenPlayed = true;
1124+ // for pattern block mark feature
1125+ if (editor.blockMarkFlag)
1126+ ui.updateStatusText = true;
11021127 }
1103− else
1128+ else // tick > 0 (handle effects)
11041129 {
1105− c = song->channels;
1106− for (i = 0; i < AMIGA_VOICES; i++, c++)
1130+ moduleChannel_t *c = song->channels;
1131+ for (int32_t i = 0; i < AMIGA_VOICES; i++, c++)
11071132 checkEffects(c);
11081133
11091134 if (posJumpAssert)
11101135 nextPosition();
11111136 }
11121137
1113− if ((editor.isSMPRendering || editor.isWAVRendering) && modHasBeenPlayed && song->tick == song->speed-1)
1114− {
1115− modHasBeenPlayed = false;
1116− return false;
1117− }
1118−
1119− return true;
1138+ return renderEndCheck(); // MOD2WAV/PAT2SMP listens to the return value (true = not done yet)
11201139 }
11211140
11221141 void modSetPattern(uint8_t pattern)
@@ -1179,7 +1198,7 @@ void modSetPos(int16_t order, int16_t row) · 56 unmodified lines
11791198
11801199 void modSetTempo(int32_t bpm, bool doLockAudio)
11811200 {
1182− if (bpm < 32)
1201+ if (bpm < 32 || bpm > 255)
11831202 return;
11841203
11851204 const bool audioWasntLocked = !audio.locked;
@@ -1195,20 +1214,20 @@ void modSetTempo(int32_t bpm, bool doLockAudio) · 9 unmodified lines
11951214
11961215 bpm -= 32; // 32..255 -> 0..223
11971216
1198− double dSamplesPerTick;
1217+ int64_t samplesPerTick64;
11991218 if (editor.isSMPRendering)
1200− dSamplesPerTick = editor.pat2SmpHQ ? audio.bpmTable28kHz[bpm] : audio.bpmTable22kHz[bpm];
1219+ samplesPerTick64 = editor.pat2SmpHQ ? audio.bpmTable28kHz[bpm] : audio.bpmTable22kHz[bpm];
12011220 else if (editor.isWAVRendering)
1202− dSamplesPerTick = audio.bpmTableMod2Wav[bpm];
1221+ samplesPerTick64 = audio.bpmTableMod2Wav[bpm];
12031222 else
1204− dSamplesPerTick = audio.bpmTable[bpm];
1223+ samplesPerTick64 = audio.bpmTable[bpm];
12051224
1206− audio.dSamplesPerTick = dSamplesPerTick;
1225+ audio.samplesPerTick64 = samplesPerTick64;
12071226
12081227 // calculate tick time length for audio/video sync timestamp
12091228 const uint64_t tickTimeLen64 = audio.tickLengthTable[bpm];
12101229 const uint32_t tickTimeLen = tickTimeLen64 >> 32;
1211− const uint32_t tickTimeLenFrac = tickTimeLen64 & 0xFFFFFFFF;
1230+ const uint32_t tickTimeLenFrac = (uint32_t)tickTimeLen64;
12121231
12131232 setSyncTickTimeLen(tickTimeLen, tickTimeLenFrac);
12141233
@@ -1238,7 +1257,7 @@ void modStop(void) · 23 unmodified lines
12381257 pattDelTime2 = 0;
12391258 pBreakPosition = 0;
12401259 posJumpAssert = false;
1241− modHasBeenPlayed = true;
1260+ modRenderDone = true;
12421261 }
12431262
12441263 void playPattern(int8_t startRow)
@@ -1246,7 +1265,7 @@ void playPattern(int8_t startRow) · 1 unmodified line
12461265 if (!editor.stepPlayEnabled)
12471266 pointerSetMode(POINTER_MODE_PLAY, DO_CARRY);
12481267
1249− audio.dTickSampleCounter = 0.0; // zero tick sample counter so that it will instantly initiate a tick
1268+ audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
12501269 song->currRow = song->row = startRow & 0x3F;
12511270 song->tick = song->speed;
12521271 ciaSetBPM = -1;
@@ -1291,7 +1310,7 @@ void modPlay(int16_t patt, int16_t order, int8_t row) · 38 unmodified lines
12911310
12921311 doStopIt(false);
12931312 turnOffVoices();
1294− audio.dTickSampleCounter = 0.0; // zero tick sample counter so that it will instantly initiate a tick
1313+ audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
12951314 ciaSetBPM = -1;
12961315
12971316 if (row != -1)
@@ -1343,8 +1362,8 @@ void modPlay(int16_t patt, int16_t order, int8_t row) · 45 unmodified lines
13431362 editor.playMode = oldPlayMode;
13441363 editor.currMode = oldMode;
13451364
1346− song->tick = song->speed;
1347− modHasBeenPlayed = false;
1365+ song->tick = song->speed-1;
1366+ modRenderDone = false;
13481367 editor.songPlaying = true;
13491368 editor.didQuantize = false;
13501369
@@ -1569,6 +1588,6 @@ void resetSong(void) // only call this after storeTempVariables() has been calle · 218 unmodified lines
15691588 doStopIt(true);
15701589
15711590 song->tick = 0;
1572− modHasBeenPlayed = false;
1591+ modRenderDone = false;
15731592 audio.forceMixerOff = false;
15741593 }

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