Browse code

[NCSF] Documented what FSS functions were originally used.

* Changed default of modDelay to 0.
* Also minor cleanup.

Naram Qashat authored on 2014/10/23 23:19:16
Showing 3 changed files
... ...
@@ -71,6 +71,7 @@ Channel::Channel() : chnId(-1), tempReg(), state(CS_NONE), trackId(-1), prio(0),
71 71
 	}
72 72
 }
73 73
 
74
+// Original FSS Function: Chn_UpdateVol
74 75
 void Channel::UpdateVol(const Track &trk)
75 76
 {
76 77
 	int finalVol = trk.ply->masterVol;
... ...
@@ -82,11 +83,13 @@ void Channel::UpdateVol(const Track &trk)
82 83
 	this->extAmpl = finalVol;
83 84
 }
84 85
 
86
+// Original FSS Function: Chn_UpdatePan
85 87
 void Channel::UpdatePan(const Track &trk)
86 88
 {
87 89
 	this->extPan = trk.pan;
88 90
 }
89 91
 
92
+// Original FSS Function: Chn_UpdateTune
90 93
 void Channel::UpdateTune(const Track &trk)
91 94
 {
92 95
 	int tune = (static_cast<int>(this->key) - static_cast<int>(this->orgKey)) * 64;
... ...
@@ -94,6 +97,7 @@ void Channel::UpdateTune(const Track &trk)
94 97
 	this->extTune = tune;
95 98
 }
96 99
 
100
+// Original FSS Function: Chn_UpdateMod
97 101
 void Channel::UpdateMod(const Track &trk)
98 102
 {
99 103
 	this->modType = trk.modType;
... ...
@@ -103,6 +107,7 @@ void Channel::UpdateMod(const Track &trk)
103 107
 	this->modDelay = trk.modDelay;
104 108
 }
105 109
 
110
+// Original FSS Function: Chn_UpdatePorta
106 111
 void Channel::UpdatePorta(const Track &trk)
107 112
 {
108 113
 	this->manualSweep = false;
... ...
@@ -130,6 +135,7 @@ void Channel::UpdatePorta(const Track &trk)
130 135
 	}
131 136
 }
132 137
 
138
+// Original FSS Function: Chn_Release
133 139
 void Channel::Release()
134 140
 {
135 141
 	this->noteLength = -1;
... ...
@@ -137,6 +143,7 @@ void Channel::Release()
137 143
 	this->state = CS_RELEASE;
138 144
 }
139 145
 
146
+// Original FSS Function: Chn_Kill
140 147
 void Channel::Kill()
141 148
 {
142 149
 	this->state = CS_NONE;
... ...
@@ -162,6 +169,7 @@ static inline int getModFlag(int type)
162 169
 	}
163 170
 }
164 171
 
172
+// Original FSS Function: Chn_UpdateTracks
165 173
 void Channel::UpdateTrack()
166 174
 {
167 175
 	if (!this->ply)
... ...
@@ -171,11 +179,11 @@ void Channel::UpdateTrack()
171 179
 	if (trkn == -1)
172 180
 		return;
173 181
 
174
-	auto &trackFlags = this->ply->tracks[trkn].updateFlags;
182
+	auto &trk = this->ply->tracks[trkn];
183
+	auto &trackFlags = trk.updateFlags;
175 184
 	if (trackFlags.none())
176 185
 		return;
177 186
 
178
-	auto &trk = this->ply->tracks[trkn];
179 187
 	if (trackFlags[TUF_LEN])
180 188
 	{
181 189
 		int st = this->state;
... ...
@@ -414,6 +422,7 @@ static inline int calcVolDivShift(int x)
414 422
 	return 4;
415 423
 }
416 424
 
425
+// Original FSS Function: Snd_UpdChannel
417 426
 void Channel::Update()
418 427
 {
419 428
 	// Kill active channels that aren't physically active
... ...
@@ -470,10 +479,11 @@ void Channel::Update()
470 479
 		}
471 480
 		case CS_RELEASE:
472 481
 			this->ampl -= static_cast<int>(this->releaseRate);
473
-			if (this->ampl > AMPL_THRESHOLD)
474
-				break;
475
-			this->Kill();
476
-			return;
482
+			if (this->ampl <= AMPL_THRESHOLD)
483
+			{
484
+				this->Kill();
485
+				return;
486
+			}
477 487
 	}
478 488
 
479 489
 	if (bModulation && this->modDelayCnt < this->modDelay)
... ...
@@ -575,10 +585,7 @@ void Channel::Update()
575 585
 			if (bModulation && this->modType == 2)
576 586
 				realPan += modParam;
577 587
 			realPan += 64;
578
-			if (realPan < 0)
579
-				realPan = 0;
580
-			else if (realPan > 127)
581
-				realPan = 127;
588
+			clamp(realPan, 0, 127);
582 589
 
583 590
 			cr &= ~SOUND_PAN(0x7F);
584 591
 			cr |= SOUND_PAN(realPan);
... ...
@@ -15,10 +15,14 @@ Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), m
15 15
 {
16 16
 	memset(this->trackIds, 0, sizeof(this->trackIds));
17 17
 	for (size_t i = 0; i < 16; ++i)
18
+	{
18 19
 		this->channels[i].chnId = i;
20
+		this->channels[i].ply = this;
21
+	}
19 22
 	memset(this->variables, -1, sizeof(this->variables));
20 23
 }
21 24
 
25
+// Original FSS Function: Player_Setup
22 26
 bool Player::Setup(const SSEQ *sseqToPlay)
23 27
 {
24 28
 	this->sseq = sseqToPlay;
... ...
@@ -38,6 +42,7 @@ bool Player::Setup(const SSEQ *sseqToPlay)
38 42
 	return true;
39 43
 }
40 44
 
45
+// Original FSS Function: Player_ClearState
41 46
 void Player::ClearState()
42 47
 {
43 48
 	this->tempo = 120;
... ...
@@ -47,6 +52,7 @@ void Player::ClearState()
47 52
 	memset(this->variables, -1, sizeof(this->variables));
48 53
 }
49 54
 
55
+// Original FSS Function: Player_FreeTracks
50 56
 void Player::FreeTracks()
51 57
 {
52 58
 	for (uint8_t i = 0; i < this->nTracks; ++i)
... ...
@@ -54,6 +60,7 @@ void Player::FreeTracks()
54 60
 	this->nTracks = 0;
55 61
 }
56 62
 
63
+// Original FSS Function: Player_Stop
57 64
 void Player::Stop(bool bKillSound)
58 65
 {
59 66
 	this->ClearState();
... ...
@@ -76,6 +83,7 @@ void Player::Stop(bool bKillSound)
76 83
 	this->FreeTracks();
77 84
 }
78 85
 
86
+// Original FSS Function: Chn_Alloc
79 87
 int Player::ChannelAlloc(int type, int priority)
80 88
 {
81 89
 	static const uint8_t pcmChnArray[] = { 4, 5, 6, 7, 2, 0, 3, 1, 8, 9, 10, 11, 14, 12, 15, 13 };
... ...
@@ -105,12 +113,12 @@ int Player::ChannelAlloc(int type, int priority)
105 113
 
106 114
 	if (curChnNo == -1 || priority < this->channels[curChnNo].prio)
107 115
 		return -1;
108
-	this->channels[curChnNo].ply = this;
109 116
 	this->channels[curChnNo].noteLength = -1;
110 117
 	this->channels[curChnNo].vol = 0x7FF;
111 118
 	return curChnNo;
112 119
 }
113 120
 
121
+// Original FSS Function: Track_Alloc
114 122
 int Player::TrackAlloc()
115 123
 {
116 124
 	for (int i = 0; i < FSS_MAXTRACKS; ++i)
... ...
@@ -127,6 +135,7 @@ int Player::TrackAlloc()
127 135
 	return -1;
128 136
 }
129 137
 
138
+// Original FSS Function: Player_Run
130 139
 void Player::Run()
131 140
 {
132 141
 	while (this->tempoCount > 240)
... ...
@@ -146,6 +155,7 @@ void Player::UpdateTracks()
146 155
 		this->tracks[i].updateFlags.reset();
147 156
 }
148 157
 
158
+// Original FSS Function: Snd_Timer
149 159
 void Player::Timer()
150 160
 {
151 161
 	this->UpdateTracks();
... ...
@@ -18,6 +18,7 @@ Track::Track()
18 18
 	this->Zero();
19 19
 }
20 20
 
21
+// Original FSS Function: Player_InitTrack
21 22
 void Track::Init(uint8_t handle, Player *player, const uint8_t *dataPos, int n)
22 23
 {
23 24
 	this->trackId = handle;
... ...
@@ -59,6 +60,7 @@ void Track::Zero()
59 60
 	this->updateFlags.reset();
60 61
 }
61 62
 
63
+// Original FSS Function: Track_ClearState
62 64
 void Track::ClearState()
63 65
 {
64 66
 	this->state.reset();
... ...
@@ -84,16 +86,18 @@ void Track::ClearState()
84 86
 	this->modType = 0;
85 87
 	this->modRange = 1;
86 88
 	this->modSpeed = 16;
87
-	this->modDelay = 10;
89
+	this->modDelay = 0;
88 90
 	this->modDepth = 0;
89 91
 }
90 92
 
93
+// Original FSS Function: Track_Free
91 94
 void Track::Free()
92 95
 {
93 96
 	this->state.reset();
94 97
 	this->updateFlags.reset();
95 98
 }
96 99
 
100
+// Original FSS Function: Note_On
97 101
 int Track::NoteOn(int key, int vel, int len)
98 102
 {
99 103
 	auto sbnk = this->ply->sseq->bank;
... ...
@@ -212,6 +216,7 @@ int Track::NoteOn(int key, int vel, int len)
212 216
 	return nCh;
213 217
 }
214 218
 
219
+// Original FSS Function: Note_On_Tie
215 220
 int Track::NoteOnTie(int key, int vel)
216 221
 {
217 222
 	// Find an existing note
... ...
@@ -247,6 +252,7 @@ int Track::NoteOnTie(int key, int vel)
247 252
 	return i;
248 253
 }
249 254
 
255
+// Original FSS Function: Track_ReleaseAllNotes
250 256
 void Track::ReleaseAllNotes()
251 257
 {
252 258
 	for (int i = 0; i < 16; ++i)
... ...
@@ -469,6 +475,7 @@ static inline std::function<bool (int16_t, int16_t)> CompareFunc(int cmd)
469 475
 	}
470 476
 }
471 477
 
478
+// Original FSS Function: Track_Run
472 479
 void Track::Run()
473 480
 {
474 481
 	// Indicate "heartbeat" for this track