Browse code

[NCSF] Correctly handle the SSEQ volume from the INFO block.

Naram Qashat authored on 2014/10/18 04:20:53
Showing 6 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Channel structures
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-05
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -71,6 +71,7 @@ Channel::Channel() : chnId(-1), tempReg(), state(CS_NONE), trackId(-1), prio(0),
71 71
 void Channel::UpdateVol(const Track &trk)
72 72
 {
73 73
 	int finalVol = trk.ply->masterVol;
74
+	finalVol += trk.ply->sseqVol;
74 75
 	finalVol += Cnv_Sust(trk.vol);
75 76
 	finalVol += Cnv_Sust(trk.expr);
76 77
 	if (finalVol < -AMPL_K)
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Player structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-15
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -11,7 +11,7 @@
11 11
 #include "Player.h"
12 12
 #include "common.h"
13 13
 
14
-Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
14
+Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseqVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
15 15
 {
16 16
 	memset(this->trackIds, 0, sizeof(this->trackIds));
17 17
 	for (size_t i = 0; i < 16; ++i)
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Player structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-13
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -19,7 +19,7 @@ struct Player
19 19
 {
20 20
 	uint8_t prio, nTracks;
21 21
 	uint16_t tempo, tempoCount, tempoRate /* 8.8 fixed point */;
22
-	int16_t masterVol;
22
+	int16_t masterVol, sseqVol;
23 23
 
24 24
 	const SSEQ *sseq;
25 25
 
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-05
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Some code from FeOS Sound System
7 7
  * By fincs
... ...
@@ -161,6 +161,33 @@ inline int Cnv_Fall(int fall)
161 161
 		return (0x1E00 / (0x7E - fall)) & 0xFFFF;
162 162
 }
163 163
 
164
+inline int Cnv_Scale(int scale)
165
+{
166
+	static const int16_t lut[] =
167
+	{
168
+		-32768, -421, -361, -325, -300, -281, -265, -252,
169
+		-240, -230, -221, -212, -205, -198, -192, -186,
170
+		-180, -175, -170, -165, -161, -156, -152, -148,
171
+		-145, -141, -138, -134, -131, -128, -125, -122,
172
+		-120, -117, -114, -112, -110, -107, -105, -103,
173
+		-100, -98, -96, -94, -92, -90, -88, -86,
174
+		-85, -83, -81, -79, -78, -76, -74, -73,
175
+		-71, -70, -68, -67, -65, -64, -62, -61,
176
+		-60, -58, -57, -56, -54, -53, -52, -51,
177
+		-49, -48, -47, -46, -45, -43, -42, -41,
178
+		-40, -39, -38, -37, -36, -35, -34, -33,
179
+		-32, -31, -30, -29, -28, -27, -26, -25,
180
+		-24, -23, -23, -22, -21, -20, -19, -18,
181
+		-17, -17, -16, -15, -14, -13, -12, -12,
182
+		-11, -10, -9, -9, -8, -7, -6, -6,
183
+		-5, -4, -3, -3, -2, -1, -1, 0
184
+	};
185
+
186
+	if (scale & 0x80) // Supposedly invalid value...
187
+		scale = 0x7F; // Use apparently correct default
188
+	return lut[scale];
189
+}
190
+
164 191
 inline int Cnv_Sust(int sust)
165 192
 {
166 193
 	static const int16_t lut[] =
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - NCSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-13
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  *
... ...
@@ -173,10 +173,9 @@ bool XSFPlayer_NCSF::Load()
173 173
 	file.data = &this->sdatData;
174 174
 	this->sdat.reset(new SDAT(file, this->sseq));
175 175
 	auto *sseqToPlay = this->sdat->sseq.get();
176
-	this->sseqVol = sseqToPlay->info.vol;
176
+	this->player.sseqVol = Cnv_Scale(sseqToPlay->info.vol);
177 177
 	this->player.sampleRate = this->sampleRate;
178 178
 	this->player.Setup(sseqToPlay);
179
-	//this->player.masterVol = sseqToPlay->info.vol;
180 179
 	this->player.Timer();
181 180
 	this->secondsPerSample = 1.0 / this->sampleRate;
182 181
 	this->secondsIntoPlayback = 0;
... ...
@@ -223,12 +222,6 @@ void XSFPlayer_NCSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
223 222
 			}
224 223
 		}
225 224
 
226
-		leftChannel = muldiv7(leftChannel, 127 - this->player.masterVol);
227
-		rightChannel = muldiv7(rightChannel, 127 - this->player.masterVol);
228
-
229
-		//leftChannel = muldiv7(leftChannel, this->sseqVol);
230
-		//rightChannel = muldiv7(rightChannel, this->sseqVol);
231
-
232 225
 		buf[offset++] = leftChannel & 0xFF;
233 226
 		buf[offset++] = (leftChannel >> 8) & 0xFF;
234 227
 		buf[offset++] = (leftChannel >> 16) & 0xFF;
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - NCSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-05
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  *
... ...
@@ -23,7 +23,6 @@ class XSFPlayer_NCSF : public XSFPlayer
23 23
 	std::vector<uint8_t> sdatData;
24 24
 	std::unique_ptr<SDAT> sdat;
25 25
 	Player player;
26
-	uint8_t sseqVol;
27 26
 	double secondsPerSample, secondsIntoPlayback, secondsUntilNextClock;
28 27
 	std::bitset<16> mutes;
29 28